PF Billing PF Billing - 1 year ago 155
HTML Question

Load Google Ads after entire page has loaded

Without Google Ads, my HTTPS webpage loads in about 500ms. With Google Ads, the same webpage takes 2-5 seconds to load. I have two banner ads (one at the top and one at the bottom). Yes, it renders the entire page before the ads, but I still think it's clunky to have the browser spinning while it waits for the ads to finish.

Is there any way with Javascript to finish page loading before the ads, and then just load the ads in the background? Basically, trick it into thinking the entire page is already loaded?

Current code:

<script async src="//"></script>
<!-- My Ad Banner -->
<ins class="adsbygoogle"
(adsbygoogle = window.adsbygoogle || []).push({});

Looking at the waterfall for my site, it doesn't look like the adsbygoogle.js is causing the load indicator. Instead, it's the actual ad content itself. For example, this object (the banner ad) doesn't even start loading until 1.8 seconds (long after my entire page has already loaded):


Answer Source

Try this article.

The trick is to put your ad initializing and loading logic in window's onload event:

   window.onload = function(){