Im wondering why people attached jQuery current version on to their website like below
//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js
rather than attaching the version that gets updated by it self like below
http://code.jquery.com/jquery-latest.js
Please let me know your thoughts on this. thanks
The first link to Google’s API is for the minified version, being only 136 bytes compared to the second links 173 bytes.
Using a CDN, the main benefit is caching. If a user has already visited a site that uses the same CDN and the same script, they will have the script already cached in the browser, but that requires that the resource is cacheable, and the “latest” version has no expires date in the header, while the link that specify the version number expires Fri, 23 Aug 2013, so in other words one of the main advantages of using a CDN for jQuery is lost when using the second link and the file is also larger. On top of that, if something changes between versions, functions that are using certain jQuery methods that are changed during a version update could break as the CDN automatically delivers the latest version.
Using the first link seems like a good idea, but in my opinion using the second link is not, and you probably would be better of just hosting the file yourself with caching enabled.
Then there’s the other reasons for using a CDN:
It increases parallelism as some browsers will only download 3 or 4 files at a time from any given site.
It reduces the amount of bandwidth used by your server as you basically get free bandwidth from the CDN.
It increases the chance that the script will already be cahced, and as more sites use the large CDN networks, more users will already have the file ready in the browser without having to download it, which speeds up your site.
It ensures that the payload will be as small as possible as Google/MS/jQuery can pre-compress the file in a wide array of formats (like GZIP or DEFLATE). This makes the time-to-download very small, because it is super compressed and it isn’t compressed on the fly, like many common webservers do.