Book Image

HTML5 Game Development by Example: Beginner's Guide

By : Seng Hin Mak
Book Image

HTML5 Game Development by Example: Beginner's Guide

By: Seng Hin Mak

Overview of this book

Table of Contents (18 chapters)
HTML5 Game Development by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
9
Building a Physics Car Game with Box2D and Canvas
Index

Time for action – adding the AppCache Manifest


Perform the following set of steps to take the game offline:

  1. In the index.html file, we add a manifest attribute:

    <html lang="en" manifest="game.appcache">
  2. Then we create a file named game.appcache with the following content:

    CACHE MANIFEST
    # 2015-03-01:v3
    
    CACHE:
    index.html
    css/matchgame.css
    images/bg.jpg
    images/deck.png
    images/popup_bg.jpg
    images/table.jpg
    js/jquery-1.11.2.min.js
    js/html5games.matchgame.js
    
    # Resources that require the user to be online.
    NETWORK:
    *
  3. In order to test the caching, we need to host the game online. Upload the project folder to a web server, then open the game and inspect the console, we should see messages about the browser downloading or using the AppCache resources, as shown in the following screenshot:

What just happened?

We just added an AppCache Manifest file to our index.html file. Now once the game is loaded, it works in offline and airplane mode.

The AppCache file

The AppCache file is a plain text file....