GoogleAdsense国内加载慢怎么解决?

编程入门 行业动态 更新时间:2024-10-10 03:29:15

GoogleAdsense国内<a href=https://www.elefans.com/category/jswz/34/1771433.html style=加载慢怎么解决?"/>

GoogleAdsense国内加载慢怎么解决?

一淘模板 56admin 发现GoogleAdsense(谷歌广告联盟)国内加载慢拖网站速度怎么解决?GoogleAdsense是谷歌旗下的站长广告联盟系统,如果站长没有好的变现渠道,挂谷歌联盟是最好的选择(日积月累),他的佣金比国内的一般平台都要高,并且以美元的方式结算。所以国内很多站长都纷纷接入了此平台,但是由于Google提供的CDN地址是国外的,导致许多国内站点接入之后拖慢了网站的加载速度,许多用户还没打开就直接关闭了,非常影响用户的体验度,非常头疼。下面小编将分享Google Adsense国内加载慢的解决方案,请大家耐心认真看完。

下面是我的原谷歌广告代码

<!-- wap*hengfuad -->
<ins class="adsbygoogle" style="display:inline-block;width:640px;height:60px" data-ad-client="ca-pub-6586051384793203" data-ad-slot="1192451801"></ins>
<script>(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<script>
window.onload = function() {setTimeout(function() {let script = document.createElement("script");script.setAttribute("async", "");script.src = ".js?client=ca-pub-6586051384793203";document.body.appendChild(script);}, 2e3);
}
</script>

有JS基础的同学都知道JS分同步和异步,异步加载不影响加载速度,所以我们这里用了定时器动态添加script标签然后给Script的src属性赋值,改善后的代码如下:

<!-- wap*hengfuad -->
<ins class="adsbygoogle" style="display:inline-block;width:640px;height:60px" data-ad-client="ca-pub-6586051384793203" data-ad-slot="1192451801"></ins>
<script>(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<script>
window.onload = function() {setTimeout(function() {let script = document.createElement("script");script.setAttribute("async", "");script.src = ".js?client=ca-pub-6586051384793203";document.body.appendChild(script);}, 2e3);
}
</script>

大家把 script.src = "" 中间的网址换为自己的网址即可。2e3 则为进入页面后等待2秒执行,你学会了吗?

 

更多推荐

GoogleAdsense国内加载慢怎么解决?

本文发布于:2024-03-14 01:46:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1735351.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   国内   GoogleAdsense

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!