script中js延遲加載示例
廣告:
基于jquery,上面是google代碼,下面是百度代碼
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-0000000000-1']);
_gaq.push(['_setDomainName', 'chinadoweb.com']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.setAttribute('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);
})();
</script>
<div class="hide">
<script type="text/javascript">
(function() {
var baidu = document.createElement('script');
baidu.type = 'text/javascript';
baidu.setAttribute('async', true);
baidu.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'hm.baidu.com/h.js?9af37----------';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(baidu, s);
})();
</script>
廣告: