Обязательно Flashcards
(140 cards)
When building a new web site or maintaining one, can you explain some techniques you have used to increase performance?
Well, performance… you mean, how fast page is loaded for user, or what?
…
In order to reduce page loading time we could to few things.
First of all, we have to understand, what step of process takes longest time. Is that connection to server, or loading a lot of heavy files, or execution of JavaScript, that we have to do before page is rendered, or something else.
If to talk about simple and often cases, well, on client side, if on our page we are using pictures, then we could compress them to make them take less memory space, so they will be loaded faster. Also, we must ensure that our code and other files are splitted into chunks of small size, and we are loading only these chunks, that we need at current moment.
On server side, we, for example, can save ofter accessed data into cache, to reduce time we need to send it to user, or, in case if on client side it takes long time to build DOM tree using complex frameworks with lot of JavaScript, then we could prebuild it on server using server side rendering, and then send to client mostly ready to use structure.
What actions have you personally taken on recent projects to increase maintainability of your code?
Okay… At first, I am trying to keep same code style, because this makes code reading much easier. This was implemented as on my current workplace, same in my pet projects. This touches indentation, naming, etcetera.
Second, is splitting code into small functional blocks, each of what contains only certain information, and I am trying to avoid code mixing, following first SOLID principle.
All in all, I am trying always remember about SOLID and KISS principles and follow them.
Can you describe your workflow when you create a web page?
Well… If we are talking about web page inside existing project with used framework, for example, Vue, then order is next.
First step is page content. This case I am thinking about what should be on the page, and what page structure would be better.
After that I create page file and add all necessary elements or framework components into template, and write JavaScript code. I also add necessary CSS, without which would be impossible to use the page.
Then I test if everything work fine, I add other CSS styles, to make page look pretty.
Finally, I make a short break, and then with fresh look return to the code, looking for possible mistakes or things I could do better.
If you have 5 different stylesheets, how would you best integrate them into the site?
Well… It depends on exact project structure and needs. But if to talk in common, then I see next solutions.
First, most simple. We can just use <link></link> html element in header to directly import all these files.
Second variant. Like first one, but this case we merge all these five files, so we get less requests to server, and lower loading time.
Third. If these styles are used to add styling to framework components, then would make sense to split them into small parts, and then import when component is loaded. This case, we don’t need to load all styles, we can just use small piece.
How would you optimize a website’s assets/resources?
Okay… At first, we should remove all assets, what we don’t really need, and load only necessary.
Second, we could load resources asynchronously, to load them in parallel.
Third, we should properly set up caching options, to reduce number of requests to server.
Finally, we can minify all code and style files, and also use compressed pictures.
Describe how you would create a simple slideshow page.
Well, that is quite simple thing, I think. At first, I would create page itself and add it into framework router. Then, talking about slideshow…
Let’s imagine, that we have certain list of images in form of list of links. This case I just add an image element on page. I set source of image to first of this links. Then, after interval, I set it as second link, then third, etcetera, until I reach last link. Then I go to first one and everything repeats.
Explain the importance of standards and standards bodies.
I think, this is important because this makes us confident in how our code will be working and how certain things should behave. Without standardization, things would be more complex and harder to work with, because code written for one case could not be used everywhere without conflicts.
What is Flash of Unstyled Content? How do you avoid FOUC?
This is period, when on page loading page content is already loaded, but styles are not, and page is shown without any styles applied to it.
We can avoid it through different mechanisms. First of all, we could put our styles in head directly or put there links to our stylesheets, to make them start loading first.
Also, we can use styles asynchronous loading using “preload” rel attribute value, and defer our main script execution until all these styles are loaded.
Explain some of the pros and cons for CSS animations versus JavaScript animations.
Okay. From one side, CSS animations are simple to declare, they are well optimized, so their performance is good, and finally, we can bind them to different states of components, like hover or active, or focus. From another side, CSS animations become quite difficult to use, when we are talking about complex animations, and also we are limited to certain set of effects.
JavaScript animations. Good sides are next: they are agile, because you have more control on process of execution, and we can execute these animations in certain cases, for example on page scrolling, or on click on certain element.
Bad side of JavaScript animations is bad performance. Also, if user disabled JavaScript execution in browser, then JavaScript animations can not work at all.
How did you handle a disagreement with your boss or your collaborator?
Well… I have certain set of rules for cases like this. First, this is important to say, that even in case of disagreement, this is necessary to be calm and polite, because rage and rudeness don’t help to solve the situation.
Well, first situation is disagreement with boss. This case, at first, I am trying to get more information about boss point of view. Maybe, I just don’t know enough, and that is the reason. On next step, if I still have disagreement, I am trying to describe my position pros and cons as fully, as only possible, because maybe just my opponent don’t understand what I want to do, and thinks about something different, and that is the source of the problem. And if anyway we didn’t reach consensus, then I usually just do as my boss told me.
If to talk about dispute with my colleagues, then, I do step one and two as I described in first case, but then if we not reached agreement, I usually go and ask somebody more experienced in dispute sphere to look on our situation and tell us what to do here.
What skills are needed to be a good front-end developer?
Well… First of all, in order to be good developer, you need to be able to work with other people on good level, because only through cooperation is possible to do something really big and valuable. You have to be polite, stay calm, and never be rude.
Second moment is personal traits. Good developer is developer who is patient and attentive to details. You have to read documentation, you have to use search engines, not always you can get information quickly, so you should have certain margin of safety to be sure that you will do everything as you have to.
Finally, of course good front-end developer should have good technical knowledge. And here I am talking more not about knowledge about certain frameworks, but about possibilities, that you can use during development. I mean, if for example I am working with button component, and my aim is to make it look pretty, I not always should remember all CSS properties, but I must remember about fundamental possibilities to change button color, or changing its border, or padding, or something else.
That were skills, which in my opinion, make a good front-end developer.
Explain the difference between cookies, session storage, and local storage?
Cookies are small pieces with limited lifetime, can be sent to server through special HTTP headers. Both server and client can read and write cookies, and this is possible to make cookies accessible only from server side, which is useful for storing authorization tokens. Usually they are used to store small pieces of information about, for example, authorization session inside application, so this case they store access token, for example.
Session storage is special key-value string storage, used to store certain information during one session. Session storage is separate for each tab. Session ends when browser closes, or this exact browser tab closes, and then this data is deleted.
Local storage is like session storage, but it is common for whole domain, and it is not deleted after tab is closed. It is usually used to store cached data or user settings.
What are data- attributes good for?
Data attributes are HTML attributes that are starting with data word. These attributes we can freely edit, because none of them are used in internal HTML mechanisms. We can use these attributes for different purposes. For example, we can save certain information about element inside these attributes. Then we can access it through JavaScript or apply CSS styles depending on the content. Also, as I know, Vue framework uses data attributes to apply scoped styles to component.
Describe the difference between <script>, <script async> and <script defer>.
Script is loaded synchronously, so browser stops document parsing until resource is loaded.
Script async works differently. When browser reaches it, it starts resource loading, but none of browser processes are paused, they go in parallel.
Script defer is like script async, but its loading starts only after page is loaded.
Why is it generally a good idea to position CSS <link>s between <head> </head> and JS <script>s just before </body>? Do you know any exceptions?
Because this case any resources, that we are loading using links, are loaded before page content render starts. This is important, because in case of styles this helps us avoid situation when page content is loaded, but unstyled.
Script is good to place before body closing tag because this case we start script execution after page content is rendered. For example, in case of frameworks, this makes us sure that all other elements on page already exist, all styles are loaded, and we can freely mount our application.
What are empty elements in HTML ?
Empty elements are elements that don’t have any content between open and close tags.
Example of these elements are image element, input, or link. All necessary information for them is provided inside element attributes, and they don’t have children nodes.
What is CSS selector specificity and how does it work?
Specificity is a rule that determines, which of styles will be applied to element when you have few conflicting styles.
It works so, that CSS looks on what of existing styles selector is most specific and uses this style to override styles with less specific selectors.
Most specific selector is inline style. CSS will always use inline style instead of any other.
Specificity for other selectors depend on many factors, including selector type and selector rule length.
I don’t remember all details, but mechanism works that way, when selector by element id is most important, then goes selector by class, and finally, selector by element type.
Describe Floats and how they work.
Float property in css allows us to make some kind of merging of two elements.
Element with float property will be displayed same way as if it had display property value “block”, it will shrink to its content size, except of cases when you directly set up width of element, and all next elements on page will flow around this element.
For example, if we have an image with fixed size and then text element after this image, and then we set up image property float value to “right”, then image will align to right side of parent container, and text element content will be shown in empty space on left side of image and below it.
Describe z-index and how stacking context is formed.
z-index is CSS property, which determines the priority of element on imaginary z-axis. In other words, elements with higher z-index will be drawn above elements with lower z-index.
Stacking context is context, that determines, which elements will be rendered below or above other elements on page.
Each element with z-index property creates stacking context. Inside this context, all children elements height on imaginary z-axis is determined by their own z-index property.
So, let’s imagine that we have certain root element, and then inside this element we have two other elements, lets name then A and B. If we set up A z-index to 10, and B z-index to 5, then A element will be drawn above B element. And if A element has children element, lets name it C, with z-index of 1, then anyway C element will be drawn above B element.
Describe BFC (Block Formatting Context) and how it works.
Block formatting context is a region where block elements positioning is handled and where floats interact with other elements.
Block formatting context is created for all float elements, also for elements with absolute or fixed position, for elements with display set to “inline-block”, “table-cell”, “flex” or “grid”, or for elements where CSS property overflow is different from “visible”.
When this can be important? For example, if we use floats. Let’s imagine that we have container without fixed width and height, inside what we have float element. This case, this element doesn’t create its own block formatting context, and this float will affect on elements outside of this container. Also, this exact element size will be 0 pixels, because float removed from default document flow.
But if we, for example, set display property of this container to flow-root, or set it overflow to hidden, or something else, what creates new block formatting context, then this container will act as separate block, its width and height will already big enough to fit float element inside them, and this float effect won’t spread out of this container.
What are the various clearing techniques and which is appropriate for what context?
There are few different techniques what I know.
First, we can add an empty element with CSS property clear set to “both” right after float elements. This case all elements after float won’t be affected.
Second case, you can put these float elements and elements, what must flow around them inside another container element, and make this container create its own block formatting context, so other elements after this container won’t be affected.
How would you approach fixing browser-specific styling issues?
Emm… Okay, lets imagine that we have few browsers and in some of them our styles are not working well.
First, I would try to detect source of problem and understand what styles and why are not applied to elements. Then, in case if that is possible, I would try to replace styles, what have problems in certain browsers with styles giving same outlook but working everywhere.
After that, if problem is not fixed, I would try to use polyfills to make it work.
Finally, if none of these things works, I would write script what would detect browser version and apply additional styles for browsers, where common approach is not working.
How do you serve your pages for feature-constrained browsers? What techniques/processes do you use?
Well, on my last job place we were using polyfills to make page look same even in old browsers.
But if to talk in common, then I know few techniques that we could use in these cases.
We could use progressive enhancement or graceful degradation strategy, to make our page work even in case if user browser does not support all features.
Then, as I said before, we can use polyfills to support newer functionality in older browsers.
Have you used or implemented media queries or mobile specific layouts/CSS?
Yes, I had. I used to work with mobile specific layouts both on my current job place and also while I was developing my CV website. In both these cases I used global Vue storages to store information about viewport size, and then depending on this information, I was adding or removing certain styles to Vue components elements. So, for example in my CV project, if viewport width is less that seven hundred eighty pixels, then I add mobile class for root element, and then depending on CSS selectors, final style of certain elements is changing.