homepage Welcome to WebmasterWorld Guest from 23.23.22.200
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Google / Google AdSense
Forum Library, Charter, Moderators: incrediBILL & jatar k & martinibuster

Google AdSense Forum

    
Adsense code in a separate js file
Merry Christmas
castor_t




msg:4049227
 11:59 am on Dec 25, 2009 (gmt 0)

Is it ok If i host adsense code in a separate js file and then include that js file in my code. I want to host the adsense code in a separate js file, so that it can be cached and shared among all of pages...

I am not sure if it is against TOS, but I am not modifying the code except that I am using a document.write(..) to display the adsense code...

 

jetteroheller




msg:4049264
 2:03 pm on Dec 25, 2009 (gmt 0)

Tests of me had shown, that the CTR is time critical with the load time of the ads.

When You load first the javasctipt,
the javascript inserts the AdSense code, this will consume some time.

So think also on all what can be criticall to CTR

incrediBILL




msg:4049347
 6:09 pm on Dec 25, 2009 (gmt 0)

Yes, but that would only impact the first page as the browser caches the javascript file so the effect on subsequent pages is faster load times, not slower.

zdgn




msg:4049359
 6:59 pm on Dec 25, 2009 (gmt 0)

that would only impact the first page

True. Depends on how much you're willing to let the time-lag impact on your first view. I'd rather have my one-view-bouncers view and click on my ad to leave the site than going back to SERPs.

Besides, it's still not clear if an external javascript include is allowed under AdSense TOS.

IanCP




msg:4049379
 8:35 pm on Dec 25, 2009 (gmt 0)

Why not simply put it in an include file as I do?

keyplyr




msg:4049381
 8:42 pm on Dec 25, 2009 (gmt 0)

Using the Adsense code in a an external file and calling in on individual pages is good webmastering.

Done this way, the Adsense file gets cached, speeding up your load time. I put the tag early in the mark-up, then float it with CSS into position on about 150 webpages, using 6 different versions. But it is the slowest component of my page since it comes from a remote server.

jomaxx




msg:4049389
 9:16 pm on Dec 25, 2009 (gmt 0)

You're using "document.write" to write out Javascript code? I've played with doing this, but IIRC it can be buggy under certain browsers/systems.

Anyway, "good webmastering" or not, the obvious thing to do is create a mockup page and ask Google for permission in writing. I did this when I needed to make another minor change to their Javascript code, and they approved it and it worked out fine.

incrediBILL




msg:4049404
 9:51 pm on Dec 25, 2009 (gmt 0)

Why not simply put it in an include file as I do?

That's exactly what we're recommending.

Depends on how much you're willing to let the time-lag impact on your first view.

When you include the code at the beginning of the page it's pre-loaded so there's no perceived delay once the page is displayed except the time it takes AdSense itself to execute which as keyplyr noted it already slow.

I don't think it's worth the effort myself because there's not enough lines of code in the AdSense part we install to really impact page load and you would be better off implementing gzip page compression if you don't already have it to improve load speed.

You're using "document.write" to write out Javascript code?

No need use document.write, it's in an include file.

Wrap it in a function call like "func AdSenseSkyScraper()" and then just call the function later in the code.

keyplyr




msg:4049406
 9:56 pm on Dec 25, 2009 (gmt 0)

@jomaxx

No, what I've done for over 3 years is to place the Adsense code(s) in an html file(s) all by itself, calling it to the page with PHP includes since all my HTML pages are served through PHP and gzip'd anyway.

johnnie




msg:4049447
 12:47 am on Dec 26, 2009 (gmt 0)

Hah! That I never thought of this :) Guess this might open up some possiblities with regard to lazy / asynchronous loading as well.

encyclo




msg:4049500
 3:39 am on Dec 26, 2009 (gmt 0)

1. Speed for the first page view is critical, which favors on-page JS.
2. The AdSense code is fairly minimalist, very little would be gained from making it external. The code already references an external file anyway (show_ads.js) where most of the JS is stored.
3. A server-side include is much faster than an external JS file.

This is a non-issue.

johnmoose




msg:4049542
 6:27 am on Dec 26, 2009 (gmt 0)

Like Keyplyr, I use php includes for the adsense code. Being a server side include, the page is rendered (with adsense code) completely before the browser sees it.
No delay on the browser (except for the external show_ads.js), only some CPU cycles on the server.

jetteroheller




msg:4049567
 9:10 am on Dec 26, 2009 (gmt 0)

All my htm and js files are GunZip compressed on the server.

The CSS is optimized to 2 kb and in the head section of the page.

So one file load less, rendering can start faster.

My typicall page size is 17 kb uncompressed, 5 kb compressed.

castor_t




msg:4049616
 2:42 pm on Dec 26, 2009 (gmt 0)

Since I use the same adsense code among all of my pages and I get huge traffic, I guess it's better using the js file, since it's downloaded once and cached. I use caching and gzip compression for my js files. I believe it's a good approach rather and more over I don't see any advantages over this approach vs. including it on the server side.

Including it in JS
(Pros)
1. Cached, Gzipped
2. Served only once to the visitors
(Cons)
1. Slow for the first time

Including it on server side
(Pros)
1. This approach is clearly not against TOS
(Cons)
1. Served for every page making the size of the page large
2. Including the file on the server side makes an additional cpu cycle

Am i missing something here?

johnmoose




msg:4049618
 2:51 pm on Dec 26, 2009 (gmt 0)

@castor_t
server side:
3. a file system cycle as the included file has to come from disk (could be cached from memory if the server is properly configured and doesn't page fault due to heavy load)

jomaxx




msg:4049676
 5:55 pm on Dec 26, 2009 (gmt 0)

incrediBILL, keyplyr: I was responding to the technique described in the initial post, which seems to be a little flaky and of only microscopic benefit, not to the PHP alternatives which are quite sensible and should be transparent to Google.

celgins




msg:4049684
 6:30 pm on Dec 26, 2009 (gmt 0)

As others have noted, a server-side include will work best. Forget about using js.

Simply place your Google code into an include file (i.e. .html, .txt, .php, .asp) and use the appropriate code within your HTML.

Some examples:

PHP: <?php include("google-stuff.txt/php/html"); ?>

ASP: <!--#include file="google-stuff.txt/asp/html"-->

keyplyr




msg:4049723
 10:00 pm on Dec 26, 2009 (gmt 0)

While I'm convinced this is an oversight in the current implementation at GWT, their Site Speed Tool currently seems to suggest the idea of moving the Adsense code to your server:


Minimize DNS lookups
The domains of the following URLs only serve one resource each. If possible, avoid the extra DNS lookups by serving these resources from existing domains:

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


Petrogold




msg:4049822
 7:07 am on Dec 27, 2009 (gmt 0)

I saw too much experiments with Adsense code is against TOS & will rather harm you than benefit you! Eventually the account might be suspended one day. Better to do other research how to bring more traffic and let the Adsense code remain as it is without any disturbance. Money will start flowing in by itself in course of time. For quick traffic what tech. are you following folks?

d3vrandom




msg:4050290
 1:40 pm on Dec 28, 2009 (gmt 0)

Everything everyone said before me is totally nuts. If your using a CMS its already loading adsense code from the database. show_ads.js cannot be loaded from your server because you never know when adsense is going to change it. And anyway why the hell would you want to do that when adsense does not permit change to code?

Also has anyone thought of the fact that the browser caches show_ads.js even when loading from google's servers? Surely its not fetching it everytime its called on the multitude of pages on the web! I just checked and on subsequent access google sends a 304 not modified header and the browser simply loads the file from cache.

civgroup




msg:4050308
 2:57 pm on Dec 28, 2009 (gmt 0)

I just checked and on subsequent access google sends a 304 not modified header and the browser simply loads the file from cache.

Don't they expire it quickly though?

levo




msg:4050316
 3:15 pm on Dec 28, 2009 (gmt 0)

max-age=86400, not too quick

jomaxx




msg:4050545
 9:36 pm on Dec 28, 2009 (gmt 0)

I think the OP was talking about moving ALL the code associated with an AdSense block into an external Javascript file, not just (or possibly not including) the show_ads file.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Google / Google AdSense
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved