简体   繁体   English

如何防止外部JS文件破坏我的网站?

[英]How can I prevent an external JS file from breaking my site?

I'm currently using Mixpanel on my site. 我目前在我的网站上使用Mixpanel。 For some reasons they go down from time to time and that disables my site from loading. 由于某些原因,它们有时会关闭,这使我的网站无法加载。

Is there a way I can make the load async or some other idea where it doesn't bring down my site when they have downtime? 有什么办法可以使负载异步或其他一些想法,使它们在停机时不会关闭我的站点?

Here's the code: 这是代码:

<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>

Thanks 谢谢

Do not document.write it to the page, append it. 不要document.write它到页面,附加它。

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM