View Single Post
  #1 (permalink)  
Old 03-24-2007, 05:05 PM
modrewrite modrewrite is offline
WebProWorld Member
 

Join Date: Dec 2006
Location: Indianapolis
Posts: 41
modrewrite RepRank 0
Default Benefits of hosting Googles urchin.js locally

Original Article

There are 2 pretty major things that you accomplish by hosting urchin.js locally
  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.

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.

Official Google Position on locally hosting urchin.js


Setup crontab by typing crontab -e at a unix-style command prompt (ssh) then add:
Code:
11 12 * * * /home/user/websites/urch.sh >/dev/null 2>&1
shell script example
Code:
#!/bin/sh
rm /home/user/websites/askapache.com/z/j/urchin.js
cd /home/user/websites/askapache.com/z/j/
wget http://www.google-analytics.com/urchin.js
chmod 644 /home/user/websites/askapache.com/z/j/urchin.js
cd ${OLDPWD}
exit 0;

One problem with the google-analytics.com/urchin.js file is that the server does not allow persistant connections.

Another big issue is that 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.com returns the entire urchin.js file all over again, thus rendering the cache-control in place voided.

You can see this problem clearly with a wireshark capture.

Code:
GET /urchin.js HTTP/1.1
Accept: */*
Referer: http://www.askapache.com
Accept-Language: en-us
UA-CPU: x86
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 3.0.04506.30)
Host: www.google-analytics.com
Connection: Keep-Alive
Code:
HTTP/1.1 200 OK
Cache-Control: max-age=604800, public
Content-Type: text/javascript
Last-Modified: Tue, 20 Mar 2007 22:54:02 GMT
Content-Encoding: gzip
Server: ucfe
Content-Length: 5675
Date: Sat, 24 Mar 2007 18:23:12 GMT
Note: You will need a caching scheme on your server for optimum results.

Overkill!
__________________
de // AskApache.com blog
Reply With Quote