HTML and CSS Reference
many of the same idioms as jQuery and is also namespace-friendly.
Do You Even Need a Library?
ments to handle different browser implementations.
Starting with jQuery
If you are already comfortable with jQuery, you may be tempted to skip this section. However, at least take a
quick glance because this section covers jQuery from a game-specific angle.
Adding jQuery to Your Page
via a <script> tag. You have two options for doing this. You can download jQuery directly, or you can load
it via a Content Delivery Network (CDN).
Loading jQuery directly means that you have complete control over the file and the page. This is both a good
and a bad thing. jQuery is a large library, and if it's not served properly (minified and compressed), it can be a
beast. jQuery 1.7 clocked in at nearly 250 kb; if served compressed and minified, however, jQuery is only 33
kb. If you are serving it directly off your web server you need to make sure you are serving a minified version
with its cache headers set correctly, so the code isn't sent on subsequent reloads. (See the next chapter for more
details on cache headers.)
Another advantage of using a CDN is that most CDNs have edge-locations around the world, meaning
wherever in the world your game players are located, they will be near a CDN server location with a fast con-
nection to the Internet. This isn't something that you can always guarantee when serving files off a standard
One last advantage of using a CDN is that, given the ubiquity of jQuery, there's a good chance that visitors
already have a CDN version of jQuery cached in their browser, meaning 0 bytes need to be sent.
To serve jQuery off the Google CDN, all you need is to add a single <script> tag to the page:
The jQuery website ( http://docs.jquery.com/Downloading_jQuery#CDN_Hosted_jQuery ) has a number of
options but the one hosted by Google is by far the most popular. To serve it locally, you need to download the
file from http://jquery.com and stick it somewhere you can access it: