Opening connection
When you load a JavaScript file synchronously in the Head
tag of an HTML page, other requested files have to wait until the JavaScript file gets downloaded. This is more visible to the end-user because, he cannot see any content until all the files in the HEAD
area get downloaded. However, using the asynchronous method to download the file we can resolve this issue to some extent.
When we specify JavaScript files to be loaded in the HEAD
section of the HTML, it is essential to know the two different ways that we can use to load the data, which are as follows:
Synchronous: The requested file will load before the parsing of the page continues
Asynchronously: The other requested files will be downloaded parallel to the requested file
So, the best practice will be the JavaScript files located in the HEAD
section of the HTML file load asynchronously. By doing so, we can eliminate page rendering delays.