異步加載:
1:在script元素中加上async屬性(為了兼容老版本的IE 加上defer)
2:動態的添加script標簽
eg:(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);
}
)();
3:通過eval()執行js代碼
延遲加載:
1:settimeOut()
2:將js放在底部