问题描述
如果没有Google广告,我的HTTPS网页会在大约500毫秒内加载。使用Google广告,同一网页需要2-5秒才能加载。我有两个横幅广告(一个在顶部,一个在底部)。是的,它在广告之前呈现整个页面,但我仍然认为在等待广告完成时让浏览器旋转是很笨拙的。
Without Google Ads, my HTTPS webpage loads in about 500ms. With Google Ads, the same webpage takes 2-5 seconds to load. I have two banner ads (one at the top and one at the bottom). Yes, it renders the entire page before the ads, but I still think it's clunky to have the browser spinning while it waits for the ads to finish.
有没有办法使用Javascript在广告之前完成页面加载,然后只在后台加载广告?基本上,欺骗它认为整个页面已经加载?
Is there any way with Javascript to finish page loading before the ads, and then just load the ads in the background? Basically, trick it into thinking the entire page is already loaded?
当前代码:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- My Ad Banner -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="myid"
data-ad-slot="myid"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
查看我网站的瀑布,看起来不像adsbygoogle.js导致负载指示器。相反,它是实际的广告内容本身。例如,此对象(横幅广告)甚至开始加载直到1.8秒(我的整个页面已经加载很久之后):tpc.googlesyndication.com/simgad/AdID
Looking at the waterfall for my site, it doesn't look like the adsbygoogle.js is causing the load indicator. Instead, it's the actual ad content itself. For example, this object (the banner ad) doesn't even start loading until 1.8 seconds (long after my entire page has already loaded): tpc.googlesyndication.com/simgad/AdID
谢谢!
推荐答案
尝试。
诀窍是将您的广告初始化和加载逻辑放在窗口的 onload
事件中:
The trick is to put your ad initializing and loading logic in window's onload
event:
<script>
window.onload = function(){
...
};
</script>
这篇关于加载整个页面后加载Google广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!