Wednesday, April 3, 2013

Why I think hosting JQuery from a 3rd party is a bad idea


...

Now that I given you time to get over my post title let me explain my logic here.

Firstly many corporates block popular sites(yes even google) that you are likely to use to host jQuery, if your site relays on jQuery to function, the user will have a very bad experience and is likely never to return to your site(when they are at home where jQuery can be loaded from google).

But it safes bandwidth?
What about all those images you are using for your templates or your pictures of cats? Anyway you are using some sort of javascript in your site somewhere and if you did it right the javascript is in a separate file, using minification technologies like https://code.google.com/p/minify/ will enable you to present the user with only one javascript file and set the appropriate caching headers while its at it.

What only one javascript download?
Yes, only one. The problem with loading resources from third party like google is the latency of pulling multiple files, lets say you are using jQuery, jQuery-ui, etc ... living in South Africa this sometimes means 200ms latency each. One javascript file with proper caching headers saves a lot of time loading your site which makes for a much better your experience.

I moved jQuery to a 3rd party CDN and it broke my javascript?
What did you think would happen if you relied on library elements before they finished loading? Using combined and minified javascript gives some control over the sequence of javascript loading.

But its already cached in the browser because of other sites?
Yes this is one good reason to let google host your javascript libraries(and not a very good one, see "But is safes bandwidth?").

My answer?
If you really are going to care about this issue to the extreme, minify and combine your css and javascript, spire your templates images and host every thing on Amazon S3.

No comments:

Post a Comment