Sunday 21 August 2016

html - External JavaScript - body or head?











Where should I put my external JavaScript file? I know that people put it at the end of the body tag to make the web page look like it loads faster. But is there any cons about putting it at the end?




And would this be a good practice to put the JavaScript with the Google Analytics code?




// Everything else over here ... conent etc..





Answer



Yes people usually put it at the end for faster page loads. What you have there with the google analytics script is common practice.



You might also want to check out head.js - this has been shown to be even faster than a single script put at the end of the body


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...