[英]How do you set the js loading sequence
我有一個網頁。 它將加載一些js文件。 其中之一是google-analytics的js ga.js文件。 我的位置在中國,所以有時加載時會很慢。
如果ga.js尚未完成加載,則不會加載另一個名為wmd.js的js文件。 因此,該網頁將無法正常工作。
因此,我想知道是否有一些設置方法,而不是在所有網絡文件加載完成后才加載ga.js?
以下是我的google-analytics設置
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '{{ settings.GOOGLE_ANALYTICS_KEY }}']);
_gaq.push(['_addOrganic', 'baidu', 'word']);
_gaq.push(['_addOrganic', 'soso', 'w']);
_gaq.push(['_addOrganic', '3721', 'name']);
_gaq.push(['_addOrganic', 'yodao', 'q']);
_gaq.push(['_addOrganic', 'vnet', 'kw']);
_gaq.push(['_addOrganic', 'sogou', 'query']);
_gaq.push(['_trackPageview']);
_gaq.push(['_trackPageLoadTime']);
(function() {
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(ga);
})();
</script>
始終,這應該是最后一個要加載的腳本。 您應該將此代碼放在結尾(在關閉body標簽之前)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.