Question: what happens when you type in a URL in the browser?
Answer: “What happens when you type in a URL” is a deceptive question commonly asked in tech interviews. If you look online, there are many very detailed resources but few concise explanations of how a web browser, a server, and the general internet work together.
This is how I would explain it:
- You enter a URL into a web browser
- The browser looks up the IP address for the domain name via DNS
- The browser sends an HTTP request to the server
- The server sends back an HTTP response
- The browser begins rendering the HTML
- Once the page is loaded, the browser sends further async requests as needed.
Question: What is the execution order of async defer and normal script ?
Answer: This image explains normal script tag, async and defer
- Async scripts are executed as soon as the script is loaded, so it doesn’t guarantee the order of execution (a script you included at the end may execute before the first script file )
- Defer scripts guarantees the order of execution in which they appear in the page.
Higher-order functions are functions that take other functions as arguments or return functions as their results.
For example, the map function on arrays is a higher-order function. The map function takes a function as an argument.
HTTP2 is here so this technique will be probably deprecated in the future. You could still use bundling for reducing the number of requests for a specific page but I don’t think it will be worth of it.
- Style declarations should be as close to the top as possible, since browsers won’t render your page before loading the CSS (to avoid a flash of unstyled content)
- Script tags should be as close to the bottom as possible, since they block browsers from parsing after the tag before it is loaded and complete (because the script may change the document with document.write)