Caching and Google's Ajax Libraries API — Cache your jQuery
Leveraging Google's free hosting of common javascript libraries seems to be getting more popular. While you should be serving all javascript concatenated and minified together, the free hosting is nice for quick jobs or more minimal projects.

The versioning system they devised is a very clever way to always serve you the most up-to-date script. For example, you request version 2 of SWFObject and it'll currently deliver 2.2, but in the future you'll always get the most recent 2.x release.
I did a bit of research on how they handle these cases, and since these facts aren't elsewhere, they needed a home. :)
The current caching rules are as follows:
| Request | Response cached for |
|---|---|
| /1.3.2/jquery.min.js | one year |
| /1.3/jquery.min.js | no caching |
| /1/jquery.min.js | one hour |
* jQuery URLs used only for illustration purposes. It's the same case with all scripts' minor/major versions
* Minified and unminified files are treated the same
Previous to now, using the google.load('jquery','1.2.6') technique was the only way to ensure the script stayed considerably cached. Direct path-based access scripts were only cached for one day. But no worries, because all is better now.
Would be cool if shorter URLs for older versions got better caching too. For example, there won’t ever be a jQuery 1.2.7, so there’s no need for short-term caching on http://ajax.googleapis.com/ajax/libs/jquery/1.2/jquery.min.js.
1.4.4 = one year = http://cl.ly/3P2l
1.4 = one hour, but "must-revalidate"? = http://cl.ly/3Ouw
1 = one hour, same as 1.4 = http://cl.ly/3Ohp
Hi Paul,
Is there a way we can cache the the ajax library as local javascript file part of individual code base?
I ask since we have used the JSAPI library to render google visualizations and there was a issue when google changed code in the jsapi library causing the entire app to go down.
I did rather do
"<script type="text/javascript" src="/jsapi.js">"
than
""
Thanks,
Rohan
With the google ajax library you can always specify the exact version of that library you want to use. Therefore it wont change on you.
That's what you want to do here.
http://code.google.com/apis/libraries/devguide.html#versioning
Paul,
Thank you for your response.
I did check out the link you provided however there is no way to get a version of jsapi. I see jquery,jQueryUI, Yahoo…. but no no jsapi which is needed for working with visualizations.
am I missing something here?
Thanks,
Rohan