should Modernizr file be placed in head?

后端 未结 4 1145
长情又很酷
长情又很酷 2020-12-23 09:16

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 thi

4条回答
  •  -上瘾入骨i
    2020-12-23 09:37

    I would argue no: every script you place in the will block rendering and further script execution. The only thing Modernizr does which must happen in the is the integrated html5shiv, which hacks HTML5 tag support into Internet Explorer 8 and earlier.

    I was testing this yesterday and found this to be fairly significant – on the site I work on, which is already fairly well optimized, adding that single script to the head delayed my load-time by ~100ms in IE9, which doesn't even benefit from the shiv!

    Since around 90% of my traffic comes from browsers which natively support HTML5 and I don't have core CSS which requires the modernizr classes to display correctly on the initial render, I'm using this approach which places the html5shiv into a conditional comment and loads modernizr without the integrated shim:

    
        
    
    

提交回复
热议问题