Is there any way to improve the speed of Google Adsense/Analytics?

5,525

Solution 1

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.

Solution 2

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 http://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.

Solution 3

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.

Solution 4

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.

Share:
5,525

Related videos on Youtube

DisgruntledGoat
Author by

DisgruntledGoat

I'm a web developer and programmer from the UK. I'll fill this out more when I can be bothered; really I'm just trying to get the autobiography badge.

Updated on September 17, 2022

Comments

  • DisgruntledGoat
    DisgruntledGoat over 1 year

    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
    www.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?

  • lyle
    lyle almost 14 years
    Are you really seeing a significant delay in page load times because of Google adsense? I have doubts about that.
  • Virtuosi Media
    Virtuosi Media almost 14 years
    On older browsers or poorly designed sites, AdSense could end up as a blocking script, preventing other page elements from downloading until it's finished. It could conceivably also affect the page paint time. I haven't noticed it much; however, this wasn't my question, it was DisgruntledGoat's. :)
  • DisgruntledGoat
    DisgruntledGoat almost 14 years
    @Kinopiko: No, I haven't experienced big delays, although if my connection slows a bit then it is noticeable when the ads are loading. As the question says, I'm asking since the recommendations in Yslow/PageSpeed are mostly related to elements I'm not sure I can control.
  • leek
    leek over 13 years
    This may be micro-optimization, but if you like the asynchronous Google Analytics snippet - check out my answer for an even faster version: webmasters.stackexchange.com/questions/1555/…
  • McDowell
    McDowell over 13 years
    excellent, we'll be looking into this as a general code pattern for JavaScript we want to load but not block (ads, basically..)
  • Stefan
    Stefan over 13 years
    I didn't know $() was a standard JavaScript function...
  • Sylverdrag
    Sylverdrag over 13 years
    @Tom: It's not, it's JQuery. Is there anyone foolish enough to code straight in JS these days?
  • Stefan
    Stefan over 13 years
    Not everybody uses jQuery by default
  • Sylverdrag
    Sylverdrag over 13 years
    @Tom: that was tongue in cheek. Yes, it would have been more accurate to say "JQuery" rather than JavaScript.