Do you have a question? Post it now! No Registration Necessary. Now with pictures!
March 31, 2007, 7:53 pm
rate this thread
Speed Up Google Analytics
This method uses crontab to execute a shell script that downloads an
updated urchin.js file every 24 hours and saves it into your local
sites directory. Thats it!
The problem occurs when google-analytics.com/urchin.js is requested by
billions of web users all over the world at one time, it can cause
your sites pages to load at a snails pace. Especially if you are using
WordPress or a similar CMS.
Official Google Position on locally hosting urchin.js
Setup crontab by typing
at a unix-style command prompt (ssh) then add:
11 12 * * * /home/user/websites/urch.sh >/dev/null 2>&1
Shell script example:
chmod 644 /home/user/websites/askapache.com/z/j/urchin.js
There are 2 pretty major things that you accomplish by hosting
1. You Enable persistant connections
2. You ensure that the correct 304 Not Modified header is sent back to
your site visitors instead of reserving the entire file.
One problem with remote hosted urchin.js is the server that the
urchin.js file is served from does not allow persistant connections.
Another big big reason is that even though Cache-Control headers are
correctly set by google-analytics when serving urchin.js, instead of
responding to an If-Modified-Since header correctly with a 304 Not
Modified header, indicating the file has not been modified, google-
analytics instead returns the entire urchin.js file again, thus
rendering the cache-control void.
You can see this problem clearly with a wireshark capture.
GET /urchin.js HTTP/1.1
Accept-Encoding: gzip, deflate
If-Modified-Since: Tue, 20 Mar 2007 22:49:11 GMT
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SU
2.011; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Alexa Toolbar; .NET CLR
HTTP/1.1 200 OK
Cache-Control: max-age=604800, public
Last-Modified: Tue, 20 Mar 2007 22:54:02 GMT
Date: Sat, 24 Mar 2007 18:23:12 GMT
Note: You will need a caching scheme on your server for optimum
Pretty sweet bit of overkill!