GoogleAdsense国内加载慢怎么解决?js异步加载解决谷歌广告拖网站速度

 1617

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

GoogleAdsense国内加载慢怎么解决?js异步加载解决谷歌广告拖网站速度

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

<!-- 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 = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.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 = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6586051384793203";
        document.body.appendChild(script);
    }, 2e3);
}
</script>

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


本文网址:https://www.zztuku.com/detail-14024.html
站长图库 - GoogleAdsense国内加载慢怎么解决?js异步加载解决谷歌广告拖网站速度
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐