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 APPS• Caution The current implementations of the application cache are fine <strong>for</strong> use by normal users, but they tendto struggle during the development phase when there are lots of changes to the manifest and lots of updatesapplied to the cache. There will come a point where you start getting odd behavior, and no changes you make toyour manifest or your application will sort matters out. When this happens, the simplest thing to do is to clear thebrowser history and application cache contents and see whether the problems persist. Most of the time, I find thatsudden changes in behavior are caused by the browser and that starting over fixes things (although thissometimes requires clearing the files directly from the disk using the file explorer, because the browser’s ability tomanage the application cache also goes awry).We can use the applicationCache browser object to manage a cached application in a more elegantway. The first thing we can do is to monitor the status of the cache and present the user with someoptions. Listing 5-5 shows how this can be done.Listing 5-5. Taking Active Control of the Application CacheCheeseLuxvar cheeseModel = {products: [{category: "British Cheese", items : [{id: "stilton", name: "Stilton", price: 9},{id: "stinkingbishop", name: "Stinking Bishop", price: 17},{id: "cheddar", name: "Cheddar", price: 17}]},{category: "French Cheese", items: [{id: "camembert", name: "Camembert", price: 18},{id: "tomme", name: "Tomme de Savoie", price: 19},{id: "morbier", name: "Morbier", price: 9}]},{category: "Italian Cheese", items: [{id: "gorgonzola", name: "Gorgonzola", price: 8},117www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!