2011-09-02 65 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