2011-09-02 61 views
1

我目前在我的網站上使用Mixpanel。由於某些原因,他們不時停下來,並禁止我的網站加載。如何防止外部JS文件破壞我的網站?

有沒有一種方法可以使負載異步或一些其他的想法,當它沒有停下來我的網站時,他們有宕機?

下面的代碼:

<script> 
    var mp_protocol = (("https:" == document.location.protocol) ? "https://" : "http://"); 
    document.write(unescape("%3Cscript src='" + mp_protocol + "api.mixpanel.com/site_media/js/api/mixpanel.js' type='text/javascript'%3E%3C/script%3E")); 
</script> 

感謝

+0

你是什麼意思「打倒你的網站」?這不像jQuery,它如何影響你的網站運作? – Rufus

+1

@Rufus,如果外部域名關閉/緩慢,如果導致頁面掛起並等待該資源。您隨時都可以通過一些糟糕的廣告服務瀏覽廣告。 – epascarello

回答

1

不要將其文件撰寫的網頁,其追加。

<script> 
$(function(){ 
    var mp_protocol = (("https:" == document.location.protocol) ? "https://" : "http://"); 
    jQuery.getScript(unescape(mp_protocol + "api.mixpanel.com/site_media/js/api/mixpanel.js")); 
}); 
</script> 
+0

並在''的底部放置'' – Rufus