Let Google Host Your Ajax Libraries

All Google conspiracy theories aside, Google actively host's popular Ajax frameworks, so why not take advantage of them?


First, if you are wondering what the advantage is, it is rather quite simple. Prototype and Script.aculo.us are very common frameworks. It makes little sense that every time a browser needs one of these popular frameworks that it needs to download it and cache it to your browser. How many copies does your browser needed? Probably just one, as you have guessed. This means every time that a framework is requested from Google, your browser already has it cached, reducing the need for another HTTP request.

But not only is this an advantage to your browser, it also is an advantage to your server, as it less files it has to serve. Less files equates to less server usage and less bandwidth.

We know that Zikula requests these dynamically, and we really do not want to hack the core files to make the redirects, so a simple work around is to have Apache make use of mod_rewrite with an .htaccess file. To keep it simple we will use the .htaccess file at the Zikula root directory.

Since .htaccess files can very with Zikula, you will have to adjust according to your situation. But It should look something like this:

# security options

php_flag register_globals off
php_flag magic_quotes_gpc off

Options FollowSymLinks
RewriteEngine On

# RewriteOptions 'inherit'
# Place our new rules about all the other rewrite rules
RewriteRule ^javascript/ajax/prototype\.js$ http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js [R=301,NC,L]
RewriteRule ^javascript/ajax/script.aculo.us\.js$ http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.1/scriptaculous.js [R=301,NC,L]

This makes a 301 redirect to Google. There you go a quick and dirty guide!

For more information see: http://code.google.com/apis/ajaxlibs/documentation/index.html

Enjoy,

-David Pahl


Share This | Print

Trackbacks

(The URL to TrackBack this entry is: http://blog.zikula.org/index.php?module=TrackBack&id=26,1-4). If your blog does not support Trackbacks you can manually add your trackback by using this form.

Comments

Comment by:
font's Avatar
font
09 Sep 2008 - 05:24AM
Thanks, David, your notes is unreplaceble for such lamers like me icon_smile
 
Comment by:
mumuri's Avatar
mumuri
19 Oct 2008 - 06:46AM
i don't think, that giving all your statistics available to google is a good idea :)

think about it
 
Comment by:
kaffeeringe.de's Avatar
kaffeeringe.de
26 Oct 2008 - 06:32PM
I use this with Yahoo's YUI stuff too. You don't throw your actually statistics at google or yahoo: Fact is, that you browser realizes that it has a cached version of the files you requests and then takes that. So it gets only fetched the first time you access the file and then it's only called locally at the client.
 
Comment by:

Anonymous
28 Oct 2008 - 07:49PM
...
^javascript/ajax/script.aculo.us\.js$
...

should be
^javascript/ajax/scriptaculous\.js$

Without the dots !!

;)
 

Add a new Comment









 
Close

You don't have permission to e-mail this story - please login