What should I do if Google ads load slowly? Detailed tutorial on optimizing loading speed
Many webmasters 'websites run Google Adsense, but we found the problem of slow loading of Google ads in the actual process of running Google ads. Is there a way to solve this problem? Today, I will bring you this detailed tutorial on optimizing Google ad loading speed.
Analysis of the reasons for slow loading of Google ads
As shown in the above figure, we divide the Google Adsense advertising code into two parts: 1 and 2. Part 1 is to load Google advertising JavaScript files. The slow speed of the web page is caused by loading this JavaScript file. The culprit for the slow speed is him.
Optimizing Google Ads Loading Speed Tutorial
The idea to solve the problem is to solve it through lazy loading, so that the website can complete loading Google advertising content.
That is to carry out lazy loading transformation of 1 part of the code:
<script type="text/javascript">
function downloadJSAtOnload() {
var element = document.createElement("script");
element.setAttribute("async", "");
element.src = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js? client=ca-Publisher ID";
element.setAttribute("crossorigin", "anonymous");
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;
</script>
The publisher ID in the above code should be changed to your own, and then add the 2 parts of code shown in the previous figure:
<ins class="adsbygoogle"
style="display:inline-block; fill in according to your code"
data-ad-client="ca-pub-fill in in your code"
data-ad-slot="4761618262"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
We can put 2 parts of code where we want to display the advertisement, and then put the modified part of code behind the 2 parts of code.
In this way, the entire process of optimizing Google's ad loading speed is over, and I hope it can help webmasters in need.
延伸阅读:
暂无内容!
评论列表 (0条):
加载更多评论 Loading...