HTML5shiv仅在HEAD部分有效? [英] HTML5shiv only works when in HEAD section?

查看:94
本文介绍了HTML5shiv仅在HEAD部分有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了尽可能快地保存我的网站,我更喜欢在文档末尾加载.js脚本,就在关闭正文标记之前,为HEAD部分保留css。但是,我发现下面的html shiv代码显然只在HEAD部分实例化时才有效。

In order to keep my sites as fast as possible, I prefer loading .js scripts at the end of the document, just before the closing body tag, reserving css for the HEAD section. However, I've found that the html shiv code below apparently only works when instantiated in the HEAD section.

<!--[if lt IE 9]>
    <script type="text/javascript" 
        src="http://html5shiv.googlecode.com/svn/trunk/html5.js">
    </script>
<![endif]-->

任何人都知道解决方法吗?

Anyone know of a workaround?

推荐答案

HTML5 shiv的工作方式需要您将其放入< head> 元素中。事实上,它在项目页面中说明了这一点:

The way the HTML5 shiv works requires you to put it in the <head> element. In fact, it says so in the project page:


要使用此脚本,必须将其包含在< body> 元素之前(即在<$ c $中) c>< head> )但是如果它出现在CSS之前或之后无关紧要 - 但为了提高性能,首先包含CSS然后是这个脚本会更有意义。 / p>

To use this script, it must be included before the <body> element (i.e. in the <head>) but doesn't matter if it appears before or after the CSS - but for the sake of performance, it would make better sense to include the CSS first then this script.

这样IE就可以在开始构建文档正文之前识别HTML5元素。

This is so IE can recognize the HTML5 elements before it starts constructing the document body.

没有解决方法。

这里的教训不是要将所有脚本放在页面末尾。 CDN在提供服务方面非常快,所以你不需要移动这个特定的脚本。 1

The lesson here is not to obsess over putting all your scripts at the end of the page. A CDN is pretty darn quick at serving stuff, so you shouldn't need to move this particular script.1

1 但正如其他人所说,由于Google Code实际上不是CDN,你应该选择另一个来源。

这篇关于HTML5shiv仅在HEAD部分有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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