一淘模板 56admin.com 发现GoogleAdsense(谷歌广告联盟)国内加载慢拖网站速度怎么解决?GoogleAdsense是谷歌旗下的站长广告联盟系统,如果站长没有好的变现渠道,挂谷歌联盟是最好的选择(日积月累),他的佣金比国内的一般平台都要高,并且以美元的方式结算。所以国内很多站长都纷纷接入了此平台,但是由于Google提供的CDN地址是国外的,导致许多国内站点接入之后拖慢了网站的加载速度,许多用户还没打开就直接关闭了,非常影响用户的体验度,非常头疼。下面小编将分享Google Adsense国内加载慢的解决方案,请大家耐心认真看完。
下面是我的原谷歌广告代码
(adsbygoogle = window.adsbygoogle || []).push({});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);}
有JS基础的同学都知道JS分同步和异步,异步加载不影响加载速度,所以我们这里用了定时器动态添加script标签然后给Script的src属性赋值,改善后的代码如下:
(adsbygoogle = window.adsbygoogle || []).push({});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.src = ""
中间的网址换为自己的网址即可。2e3
则为进入页面后等待2秒执行,你学会了吗?
你可能想看:
发表评论
共有[ 0 ]人发表了评论