Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

should Modernizr file be placed in head?

Should the reference to the Modernizr JavaScript file be in the head of the page? I always try and place all scripts on the bottom of the page and would like to preserve this. And if it needs to be in the head, why?

like image 692
amateur Avatar asked Jun 07 '11 23:06

amateur


People also ask

Where do you put scripts in head or body?

Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.

Can we add script tag in head?

You can add JavaScript code in an HTML document by employing the dedicated HTML tag <script> that wraps around JavaScript code. The <script> tag can be placed in the <head> section of your HTML or in the <body> section, depending on when you want the JavaScript to load.

What is the use of Modernizr?

Modernizr is a JavaScript library that detects which HTML5 and CSS3 features your visitor's browser supports. In detecting feature support, it allows developers to test for some of the new technologies and then provide fallbacks for browsers that do not support them.


1 Answers

If you want Modernizr to download and execute as soon as possible to prevent a FOUC, put it in the <head>

From their installation guide:

Drop the script tags in the <head> of your HTML. For best performance, you should have them follow after your stylesheet references. The reason we recommend placing Modernizr in the head is two-fold: the HTML5 Shiv (that enables HTML5 elements in IE) must execute before the <body>, and if you’re using any of the CSS classes that Modernizr adds, you’ll want to prevent a FOUC.

like image 115
Wesley Murch Avatar answered Oct 06 '22 00:10

Wesley Murch