Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

load show_ads.js once

So we run google ads on our sites.

And I got thinking, each ad block ( of various sizes ) loads ..

<script type="text/javascript"
            src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

eg:

<script type="text/javascript"><!--
            google_ad_client = "ca-pub-xxxxxxxxxxxxxx";
            /* ad served */
            google_ad_slot = "xxxxxxxxx";
            google_ad_width = 728;
            google_ad_height = 90;
            //-->
            </script>
            <script type="text/javascript"
            src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
        </script>

and other ads, of different slot ( id's ) amd sizes, on the same page also load :

http://pagead2.googlesyndication.com/pagead/show_ads.js

each time. So a page with say three ads on, loads that exact same js file 3 times ..

Removing that script file, adding it ONCE to the head, doesnt work for us.. the ads just dont show.

So is there a method of loading that show_ads.js file just once / page load ?

like image 802
422 Avatar asked May 31 '12 22:05

422


1 Answers

The Google ads script utilizes document.write(), which means the script must be in the position in the HTML that you want the ad.

However, fear not: the show_ads.js file will only be downloaded by your browser once. The subsequent <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js">s will load from cache.

In fact, the Cache-Control headers tell your browser it can load the file directly from cache for the next hour, so there should be only one trip to pagead2.googlesyndication.com per session, no matter how many pages are viewed.

like image 183
josh3736 Avatar answered Nov 14 '22 17:11

josh3736