I am working on a rails application that uses big javascript libraries (e.g. jquery UI), and I also have a handful of my own javascript files. I'm using asset packager to package up my own javascript. I'm considering two ways of serving these files:
Link to the jQuery libraries from Google Code as described at http://code.google.com/apis/ajaxlibs/documentation/#jquery , and separately package up and serve my javascript files using asset packager.
Host the jquery libraries myself, and package them together with my own javascript as one big merged javascript file.
My hosting solution is of course not going to beat out Google's content delivery network, so at first I assumed that end users would experience faster page loads via option #1.
However, it also occured to me that if I serve them myself, users would only need to issue one request to get the merged javascript (as opposed to one for my merged javascript and another for the libraries served by google).
Which approach will provide the best end-user experience (presumably in the form of faster load times?)
I would say "it depends", but in most cases I'd go with Option #1 (Google hosting) for an internet facing site. For an intranet I'd host everything internally for a number of reasons, but that's outside the scope of your question it looks like.
There's a few things to consider overall:
You can host all the files in one file, but you have to consider the weight of a few things with this:
Depending on what percentage of the code is custom and how much is framework, Google's CDN can take a substantial part of your static js traffic off your server, leaving it available to serve and do other things (that's a huge benefit to a high traffic site), and when you change your script (much more common than a new framework release)...the client downloads only that, not the entire framework again.
The nice thing about Google is that because it is used by many websites, chances are that a user will have already viewed a site that used the google JS libraries, in which case, it would already be cached on their machine, and they might not need to download the file at all.
Personally, I would stick with using Google (via the google.load()) instead of trying to combine the files and load them from my own server. (You can also use google's loader to lazy-load the files, and only load them when you need them, rather than loading all your libraries and only using 1 of them.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With