ounvna
Last Updated: February 25, 2016
·
775
· amirtcheva

It doesn't matter where you place your jQuery scripts

From: http://railsapps.github.io/rails-javascript-include-external.html

"a word about persistent folklore. You may have encountered the frequently repeated advice to “always place JavaScript at the bottom of the page just before the closing </body> tag”. This was once true because web browsers loaded scripts sequentially and blocked loading and rendering until each script was complete. This is no longer true; modern browsers do “preload scanning” and begin loading all scripts in parallel, whether listed in the head element or at the bottom of the page. External JavaScript often is loaded asynchronously and is written so it won’t execute until the page is loaded and the DOM is ready. Loading a script in the head element is no longer a bad practice.

3 Responses
Add your response

12422

What is a "modern browser" in this case, and is there any reason NOT to put script refs at the bottom of the page?

over 1 year ago ·
12423

I assume he means the evergreens (chrome, firefox, to some extent safari) and possibly IE9 or 10+

http://browsehappy.com

over 1 year ago ·
12527

Most browsers (possibly excluding Opera), and the latest versions of IE.

@johnbubriski There doesn't seem to be a reason not to place them at the bottom, unless you have other scripts that depend on the jQuery library that are used before it's loaded (which I've had issues with).

over 1 year ago ·