延迟加载JavaScript

上代码:

这段代码放到HTML文档的</body>标签之前(靠近HTML文档底部)。外部脚本的名称为defer.js

<script type="text/javascript">

function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "defer.js";
document.body.appendChild( element );
} if ( window.addEventListener ) {
window.addEventListener( "load", downloadJSAtOnload, false );
} else if ( window.attachEvent ) {
window.attachEvent( "onload", downloadJSAtOnload );
} else {
window.onload = downloadJSAtOnload;
}
</script>

参考:

http://www.cnblogs.com/yangyoucun/p/6337360.html#undefined

上一篇:【目录】Spring 源码学习


下一篇:Java学习笔记之MyEclipse 2017 CI 7、CI 8、CI 9和CI 10的安装与激活