Page Speed and AdSense

Hey Everyone,

I am trying to avoid inline JavaScript as much as I can. I am also trying to have all my JavaScript execute after the onload event takes place. I know Google stated in their TOS that publishers are not allowed to modify their code. I have a few questions about this:

#1 - Can Google Adsense be loaded asynchronously without violating their TOS? When it is synchronous and inline, it may delay the body onload event from occurring.

#2 - Can Google Adsense be placed into a function that is called after the body onload event takes place without violating their TOS?

#3 - Can Google Adsense JavaScript be placed into an external JS file without violating their TOS?

#4 - Can Google Adsense be placed into a frame (with no content) as long as the frame is part of a bigger page (with content) without violating their TOS? I am thinking the frame src value could be set once the body onload event occurs.

#5 - How do you increase your page speed when dealing with ad systems such as Google without violating any rules?

Thanks in advance for any suggestions and / or information.

Travis Walters

My best suggestion for dealing with Adsense is to wait.

Google mentioned at Velocity that they were in testing with a non-blocking version of the adsense code (just working out some final kinks). Surprised there wasn’t more written about it - this is the only article I could find:

Hey Patrick,

I posted a thread on the Google Adsense forum as well:

It seems there is some sort of document.write code in the AdSense code that prevents the code from being placed after the body onload event occurs.

Concerning iframes, I found a few materials as well:

The second link is from Google obviously. It contradicts the first link so I emailed Google about it to see if it is within their TOS. I checked out your link as well. It is nice to see Adsense is creating a non-blocking script. I just want to make sure I stay within their TOS because I do not want to lose my account. Even the Google Products is based through AdSense.

Travis Walters


Well, the root javascript is far futures expires, and all it seems to do is write an iframe which loads in async. - atleast thats what i gathered from the velocity video

adsense JS uses the evil document.write it has to be run exactly where the ad would be placed. - so the TOS is least of your worries here

See #2

I believe this is possible, but the user is more likely to have the adsense JS in cache than your frame. Im not 100% clear if this is ok or not as per TOS, but your eCPM/targeting may be effected. test first.

I deal with much much worse(in terms of speed) ad networks. to overcome blockage due to their crappy systems, i use DFP’s experimental iFrame tagging.

Using DFP also has other benefits, you can sell ads any moment with option to fallback to adsense…

IMHO if you wanna use only adsense, your only way to mitigate the issue is to use source ordered content where the adsense code is lower than your important studd in the HTML. This does absolutely nothing to improve your pageload time, but it improves perceived latency.

hi Sajal,

I did some research on Adsense and blocking page load/rendering.
My findings (and solution) are documenten in a blog post:

Maybe this helps you. Let me know!

Hi Aaron,

Very interesting research and solution. I used to use this trick when directly embedded other much crappier ad networks directly on my pages.

For this solution this just maybe violation of Adsense TOS… im not sure… maybe ill try to get my rep to confirm if this is ok.

This makes putting Adsense directly (using your method) more optimal than putting it via DFP if one doesnt need other DFP features…


If your pages are loading quickly then all the ads will be displayed to the customers quickly.Also they can contact to the advertisers for the products or services.But if your page is loaded with more than 1mega byte then the will not be loaded easily.So both the publishers and the advertisers will be affected.So the advertising campaign will not be effective.