Mobile app version of vmapp.org
Login or Join
Yeniel560

: Is there any way to improve the speed of Google Adsense/Analytics? Whenever I run Google Page Speed or YSlow, many of the optimisations suggested stem from my use of Google Adsense and Google

@Yeniel560

Posted in: #GoogleAdsense #GoogleAnalytics #Performance

Whenever I run Google Page Speed or YSlow, many of the optimisations suggested stem from my use of Google Adsense and Google Analytics.

For example, YSlow says there are "9 external Javascript scripts" - I only have one on my site, so the rest are obviously from either adsense or analytics. Also under "Reduce DNS lookups", these domains are listed:


pagead2.googlesyndication.com
googleads.g.doubleclick.net
google-analytics.com altfarm.mediaplex.com
img-cdn.mediaplex.com
eu.bid.invitemedia.com
ad.doubleclick.net
s0.2mdn.net
pixel.invitemedia.com
adadvisor.net


Is there anything I can do to reduce these or make other improvements to the speed?

10.06% popularity Vote Up Vote Down


Login to follow query

More posts by @Yeniel560

6 Comments

Sorted by latest first Latest Oldest Best

 

@Shelton105

If you like the asynchronous Google Analytics script, check out Mathias Bynens optimization to it here. Obviously, you should keep up to date on whether Google changes the snippet significantly - but for now, his optimizations yields a 40% speedup (for me) over Google's version of the same script.

10% popularity Vote Up Vote Down


 

@Gail5422790

If this is an issue, what you can do is load the page without those scripts, and then import the scripts into the page using ajax, after the page is fully loaded

For instance, let's say you have an empty div on your page, like this:

<div id="adsenseBanner"></div>


And you then append the javascript like this:

$(document).ready(function(){
$('#adsenseBanner').append('<script>alert("this");</script>')
});


I added a JavaScript alert so you can see that it is being executed, but of course, you would replace it with the scripts you need to load.

This way, you can be sure that these external resources don't slow down your page load... at the cost of loading one extra script.

10% popularity Vote Up Vote Down


 

@Sims2060225

Just one point - there is a new version of google analytics code which should improve it's loading speed - so it might be worth changing to that.

10% popularity Vote Up Vote Down


 

@RJPawlick198

Loading Google Analytics Asynchronously is a good start. Beyond that, how long does it take your page to load? If it takes you page less than 2 seconds then you may not want to spend the time optimizing it any more.

If you are concerned that it would load slower from elsewhere, checkout www.webpagetest.org/ to test you page against other locations around the world and other internet speeds. This page will also show you how long each chunk of your site is taking to load.

You have to remember that it is probably not useful to make your page load at a "perfect speed" because the cost in time and energy is too high. If you can get your page below 2 seconds, according to Google, you will be in the top 20% of websites and that is probably good enough. If not, look where else you can increase you page speed. Sometimes fixing a bunch of smaller things will make you site fast enough.

The best way to put it, I think, is pick the low hanging fruit and Google Adsense isn't low hanging really. Analytics is and should be easy enough to fix by making it asynchronous and maybe you should leave it at that.

10% popularity Vote Up Vote Down


 

@Caterina187

Generally a lot of these ad scripts are 'cache-busted' purposefully, so that a hit is made to the server every single time to register the view.

Unfortunately just using adsense means that you've opened yourself up to a hell of a lot of external javascripts and there's really not much you can do about it other than decreasing the number of ad zones (TOS only allows 3 per page anyway) or just not running adsense.

You could try wrapping up your google ads javascript in your own hosted javascript for each zone that did a document.write and output the required code. I'm pretty sure this would cause it to load after the body has loaded and therefore mean your page will load first.

10% popularity Vote Up Vote Down


 

@Deb1703797

Google Analytics can be set up so that it loads asynchronously, which will help improve the situation. It doesn't look like they currently have a similar script for AdSense.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme