简体   繁体   English

Javascript脚本可防止等待脚本加载(PantherAds)

[英]Javascript script prevent waiting for script to load (PantherAds)

Well I recently got into PantherAds and got my ad script to place on my website. 好吧,我最近接触了PantherAds,并将广告脚本放到我的网站上。 However I found out that when the script (/iframe) of Pantherads on my website isn't loading, the rest of my website isn't loading either. 但是我发现,当我的网站上的Pantherads脚本(/ iframe)未加载时,我网站的其余部分也均未加载。 In other words: it's waiting for Pantherads to fully load before it will continue to load the rest of my website. 换句话说:它正在等待Pantherads完全加载,然后才能继续加载我的网站的其余部分。 Now what I'd like to do is either make sure it loads the rest of the page at the same time, so that my website won't be bothered when PantherAds script isn't loading, or I'd like to set a timeout for the Pantherads script. 现在,我要做的就是确保同时加载页面的其余部分,以便在不加载PantherAds脚本时不会打扰我的网站,或者我想设置超时时间Pantherads脚本。 Eg if it hasn't loaded within 5 seconds, then just skip it. 例如,如果5秒钟之内没有加载,请跳过它。

Does anyone know how to do this? 有谁知道如何做到这一点? Or can anyone help me out on this? 或者有人可以帮我这个忙吗? Would be much appreciated! 将不胜感激!

Thanks in advance. 提前致谢。

Best Regards. 最好的祝福。

UPDATE: This is the Pantherads script: 更新:这是Pantherads脚本:

<script language="javascript" type="text/javascript" src="http://pantherads.com/ads/CODEHERE"></script>

It's said to use an iframe to show the ad. 据说使用iframe来展示广告。

There are 3 different solutions: 有3种不同的解决方案:

  • add the "async" attribute to the script declaration ( 在脚本声明中添加“异步”属性(
  • add the "defer" attribute. 添加“ defer”属性。 It's supported by all browsers (even by IE5). 所有浏览器(甚至IE5)都支持它。 I will delay the script execution until the body is not fully parsed/rendered. 我将延迟脚本执行,直到正文未完全解析/渲染为止。
  • place you script just before the end of the page (, suggested by Jashwant) 将脚本放在页面末尾之前(由Jashwant建议)

PS if I were you I would review the entire execution/priority map of all the scripts, by putting some of them (mostly Google analytics and similar) to async mode. PS:如果您是我,我会通过将其中一些脚本(主要是Google Analytics(分析)等)置于异步模式来查看所有脚本的整个执行/优先级映射。 JQuery external scripts to defer and so on. jQuery延迟外部脚本等等。 You might get a significant speed increase. 您可能会大大提高速度。

Include your <script> </script> tags of PantherAds just before closing </body> tag. 在关闭</body>标签之前,先添加PantherAds的<script> </script> </body>标签。

It will load only after your page is loaded. 仅在加载页面后才加载。

Google, and many others use the following JavaScript snippet to perform an async load of a JavaScript file; Google和其他许多人使用以下JavaScript代码段执行JavaScript文件的异步加载; just add the following code to a script block on your page: 只需将以下代码添加到页面上的script块中:

(function() {
    var s = document.createElement('script');
    s.type = 'text/javascript';
    s.async = true;
    s.src = 'http://pantherads.com/ads/CODEHERE';
    var x = document.getElementsByTagName('script')[0];
    x.parentNode.insertBefore(s, x);
})();

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

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