Article introduction of Wulin.com (www.vevb.com): html5 offline application description I won’t say much here. Please Google or Baidu. This article aims to introduce how to realize offline application development
I won’t talk about the instructions for offline application here. Please Google or Baidu. This article aims to introduce how to realize offline application development;
Step 1: Create a manifest file and specify a cache file manifest;You can first create a new file with txt text format suffix, and the first line must be written to CACHE MANIFEST;
The second line optionally writes a comment description #version 1.0, and the comment starts with #, which means to specify the version number;
The third line starts with a file path relative to the current file directory, such as:
static/img/logo.png
static/css/style.css
A basic manifest file is written, and the suffix of this file is changed to . manifest;
Step 2: In the html file, specify the document's manifest property as the path of the cache.mnifest file;<html manifest=cacheData.manifest>
After adding the manifest attribute, load the page, the files in the cache configuration file will be cached offline and will not be read from the server when refreshed again;
Step 3: Refresh the cache through the API interface;Use JS to obtain offline cache objects through window.applicationCache, and call the update method: window.applicationCache.update() to call the download of the current cache file. After the download is completed, the updateready event of the offline cache object will be triggered. Execute the swapCache method to clear the cache: window.applicationCache.swapCache() . This will not cause the previously loaded resources to be suddenly reloaded, but the resources that issued the request page after this are the latest;
Through the above three simple steps, you can realize HTML5 offline application.