How to solve the slow loading of Google Adsense in China?

 

The author found that Google Adsense (Google Advertisement Alliance) is slow to load in China and slows down the speed of the website. How to solve it? Google Adsense is a webmaster advertising alliance system under Google. If the webmaster does not have a good monetization channel, it is the best choice to link to Google Alliance (accumulated over time). His commission is higher than that of ordinary domestic platforms, and it is paid in US dollars. settlement. Therefore, many domestic webmasters have connected to this platform one after another, but because the CDN address provided by Google is foreign, many domestic sites have slowed down the loading speed of the website after accessing it, and many users have closed it directly before opening it. Affecting the user experience is a headache. The following editor will share the solution to the slow loading of Google Adsense in China, please read it patiently.

934c9fa37bf2475a96a50f2f13664dbd.jpeg

 

Below is my original google ad code

<!-- 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>

Students with JS foundation know that JS is divided into synchronous and asynchronous, and asynchronous loading does not affect the loading speed, so we use a timer to dynamically add script tags and then assign values ​​to the src attribute of the script. The improved code is as follows:

<!-- 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>

Just replace  script.src = "" the URL in the middle with your own URL. 2e3 Then wait for 2 seconds to execute after entering the page, have you learned it?

 

 

Guess you like

Origin blog.csdn.net/qq974416775/article/details/131176454