12.07.2015 Views

Pro JavaScript for Web Apps pdf - EBook Free Download

Pro JavaScript for Web Apps pdf - EBook Free Download

Pro JavaScript for Web Apps pdf - EBook Free Download

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 5 CREATING OFFLINE WEB APPSListing 5-3. Adding the Manifest to the HTML Document......When the HTML document is loaded, the browser detects the manifest attribute, requests thespecified appcache file from the web server, and begins loading and caching each file listed in themanifest file. The files that are downloaded when the browser processes the manifest are called theoffline content. Some browsers will prompt the user <strong>for</strong> permission to store offline content.• Caution Be careful when you create the manifest. If any of the items listed cannot be obtained from the server,then the browser will not cache the application at all.Understanding When Cached Content Is UsedThe offline content isn’t used when it is first loaded by the browser. It is cached <strong>for</strong> the next time that theuser loads or reloads the page. The name offline content is misleading. Once the browser has offlinecontent <strong>for</strong> a web app, it will be used whenever the user visits the web app’s URL, even when there is anetwork connection available. The browser takes responsibility <strong>for</strong> ensuring that the latest version of theoffline content is being used, but as you’ll learn, this is a complicated process and requires someprogrammer intervention.I commented out the blackwave.png file in the manifest to demonstrate how the browser handlesoffline content. I use blackwave.png as the background image <strong>for</strong> the CheeseLux web app, and this givesme a nice way to demonstrate the basic behavior of a cached web application.To start with, add the manifest attribute to the example as shown in Listing 5-3, and load thedocument into your browser. Different browsers deal with cached applications in different ways. Forexample, Google Chrome will quietly process the manifest and start downloading the content itspecified. Mozilla Firefox will usually prompt the user to allow offline content, as shown in Figure 5-1. Ifyou are using Firefox, click the Allow button to start the browser processing the manifest.113www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!