Need to provide a cache manifest file to work out all the resources that need to be used offline
For example
Manifest code
1 CACHE MANIFEST2 #这是注释3images/sound-Icon.png4images/Background.png5 clock.html6 Clock.css7 Clock.js8 9 NETWORK:Ten test.cgi One A CACHE: -style/default. CSS - the FALLBACK: -/files/projects/projects
1 2 3 HTML5 Offline application update cache mechanism 4 divided into 2 types of manual and Automatic Updates 5 Automatic Updates: 6 Update of cached resource files changes when the cache manifest file itself changes does not trigger an update 7 Manual Update: 8 using Window.applicationcache 9 JS Code
1 if (Window.applicationCache.status = = Window.applicationCache.UPDATEREADY) { 2 window.applicationCache.update (); 3 }
On-line status detection
HTML5 provides two ways to detect online:navigator.online (True/false) and online/offline events.
Build offline Apps in Android
Java code
1 //turn on application caching2Websettingssetappcacheenabled (true); 3String dir = This. Getapplicationcontext (). Getdir ("Cache", Context.mode_private). GetPath (); 4 //set the path to the app cache5 Websettings.setappcachepath (dir); 6 //set the mode of the cache7 Websettings.setcachemode (Websettings.load_default); 8 //set the maximum size of the app cache9Websettings.setappcachemaxsize (1024*1024*8); Ten One //capacity of the extended cache A Public voidOnreachedmaxappcachesize (Longspaceneeded, - LongTotalusedquota, Webstorage.quotaupdater quotaupdater) { -Quotaupdater.updatequota (spaceneeded * 2); the}
Using HTML5 to develop Android (6)---build HTML5 offline applications