JS异步加载的方式
2021-04-08 17:28
标签:firefox ready tac util UNC dde cti 兼容 list 方法一:Script Dom Element JS异步加载的方式 标签:firefox ready tac util UNC dde cti 兼容 list 原文地址:https://www.cnblogs.com/jayfeng/p/12458082.html
(function(){
var scriptEle = document.createElement("script");
scriptEle.type = "text/javasctipt";
scriptEle.async = true;
scriptEle.src = "http://cdn.bootcss.com/jquery/3.0.0-beta1/jquery.min.js";
var x = document.getElementsByTagName("head")[0];
x.insertBefore(scriptEle, x.firstChild);
})();
(function(){;
var ga = document.createElement(‘script‘);
ga.type = ‘text/javascript‘;
ga.async = true;
ga.src = (‘https:‘ == document.location.protocol ? ‘https://ssl‘ : ‘http://www‘) + ‘.google-analytics.com/ga.js‘;
var s = document.getElementsByTagName(‘script‘)[0];
s.parentNode.insertBefore(ga, s);
})();
(function(){
if(window.attachEvent){
window.attachEvent("load", asyncLoad);
}else{
window.addEventListener("load", asyncLoad);
}
var asyncLoad = function(){
var ga = document.createElement(‘script‘);
ga.type = ‘text/javascript‘;
ga.async = true;
ga.src = (‘https:‘ == document.location.protocol ? ‘https://ssl‘ : ‘http://www‘) + ‘.google-analytics.com/ga.js‘;
var s = document.getElementsByTagName(‘script‘)[0];
s.parentNode.insertBefore(ga, s);
}
})();
$(document).ready(function() {
alert("加载完成!");
});
script
type="text/javascript" src="http://www.soscw.com/xxx.js" async="async">
script
>
script
type="text/javascript" defer>
script
>
script
type="module" src="http://www.soscw.com/XXX.js">
script
>
script
type="module">
import utils from "./utils.js";
// other code
script
>