Script 元素 type 属性的妙用
我们经常使用动态创建 JavaScript 的方式来实现 JavaScript 文件的无阻塞(Non-blocking)、并行下载(Parallel )。其实还可以添加自定义的 type 属性(比如 text/cache),达到预加载但不执行的效果:
var doc = document,
el = doc.createElement("script"),
head = doc.getElementsByTagName('head')[0];
el.src = "http://yui.yahooapis.com/2.8.2r1/build/yahoo-dom-event/yahoo-dom-event.js";
el.type = "text/cache";
head.insertBefore(el, head.firstChild);
注:Firefox 3.6.x 不请求 JavaScript 文件。
本文出自 传播、沟通、分享,转载时请注明出处及相应链接。
本文永久链接: https://www.nickdd.cn/?p=1404