O'Reilly logo

Professional HTML5 Mobile Game Development by Pascal Rettig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

The jQuery library consists of a single JavaScript file. To load jQuery on your page, you need to load this file 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 connection to the Internet. This isn’t something that you can always guarantee when serving files off a standard web server.

One last advantage of using a CDN is that, given the ubiquity of jQuery, there’s a good chance ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required