Speed Up Google Analytics
Speed Up Google AnalyticsThis 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 crontab -e at a unix-style command prompt (ssh) then add: 11 12 * * * /home/user/websites/urch.sh >/dev/null 2>&1 Shell script example: #!/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;
There are 2 pretty major things that you accomplish by hosting urchin.js locally:
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
HTTP/1.1 200 OK Note: You will need a caching scheme on your server for optimum results. Pretty sweet bit of overkill!
|







Recent comments
2 days 19 hours ago
4 days 15 hours ago
5 days 18 hours ago
6 days 5 hours ago
6 days 20 hours ago
1 week 6 hours ago
1 week 11 hours ago
1 week 17 hours ago
1 week 2 days ago
1 week 2 days ago