1.调整标签位置
可以把<script>标签放到HTML文档的最后面,这样不影响页面加载。
2.动态创建script来加载
loadJS('js/index.min.js?V=1.0.0.1',function(){ //加载,并执行回调函数 //alert('动态引入js成功') }); function loadJS(url, callback) { var script = document.createElement('script'), fn = callback || function() { }; script.type = 'text/javascript'; // IE if (script.readyState) { script.onreadystatechange = function() { if (script.readyState == 'loaded' || script.readyState == 'complete') { script.onreadystatechange = null; fn(); } }; } else { // 其他浏览器 script.onload = function() { fn(); }; } script.src = url; document.getElementsByTagName('head')[0].appendChild(script); }
参考:
http://www.javacui.com/javascript/568.html
https://www.jb51.net/article/139481.htm
https://www.jb51.net/article/139504.htm?proxy=1