应该将Modernizr文件放在首位吗? [英] should Modernizr file be placed in head?

查看:68
本文介绍了应该将Modernizr文件放在首位吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对Modernizr JavaScript文件的引用应该在页面的顶部吗?我总是尝试将所有脚本放在页面底部,并希望保留它.如果需要在脑子里,为什么?

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?

推荐答案

如果要 Modernizr 下载并尽快执行以防止 FOUC ,将其放入<head>

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

摘自他们的安装指南:

将脚本标签放到<head>的 您的HTML.为了获得最佳性能,您 应该让他们跟随你的 样式表参考.我们之所以 建议将Modernizr放在 头有两个方面:HTML5 Shiv(即 必须在IE中启用HTML5元素) 在<body>之前执行,如果 您正在使用任何CSS类 加上Modernizr,您将想要 防止FOUC.

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.

这篇关于应该将Modernizr文件放在首位吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆