Tuesday 14 November 2017

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..

type="text/javascript">

// google analytics code





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 href="http://headjs.com/" rel="noreferrer">head.js - this href="http://headjs.com/#theory" rel="noreferrer">has been shown to be even
faster than a single script put at the end of the body



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...