Using hosted jquery

En kort genomgång om hur och varför man ska använda googles jquery hosting istället för att ha filerna på den egna servern.

If you are using jquery or jqueryui then make sure that you don’t keep the library itself on your own server. Google, and other companies, are hosting the files you need to use jquery and jqueryui (google also hosts its own jquery-json library).

This has several advantages:

  • You don’t need to host the files yourself
  • You don’t need to care about users who can only download using a certain amount of connections to your server
  • Caching
  • The distance to your user (wherever your server is located, there is always a google server closer to your user)

This means that instead of writing like this:

<script type="text/javascript" src="/javascript/jquery-1.4.4.js"></script>

You write it like this:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

Now you never have to care where you keep your jquery libs. You’ll also know that you’ll be cutting down loading time on your page as most users hopefully have the libraries cached on their computers. So all you have to do is change the version number whenever you feel like upgrading you libraries.

JQuery:
http://code.google.com/intl/sv-SE/apis/libraries/devguide.html#jquery

JQuery – Google JSON Library:
http://code.google.com/p/jquery-json/

JQueryUI:
http://ajax.googleapis.com/ajax/libs/jqueryui/[UI-VERSION]/themes/[THEME-NAME]/jquery-ui.css

The JQueryUI must be used with a defined theme (in the URL there is a [THEME-NAME] section which must be replaced with a propert theme name and UI-VERSION must be changed to version). Here’s a couple of the themes available (all can be found on this google blog). In general any theme name from the jqueryui.com theme gallery can be used:

Leave a Reply