[Html5]app offline cache (application cache)

Source: Internet
Author: User
Tags event listener

Therefore, this interface is to let Web pages or files in the local cache, the advantage is that it can improve the loading speed of the site, in the same way, if you cache all files locally, you can browse the Web page offline.

We can cache those frame files and the old image files locally, increasing the load speed of the site two views.

1. First create a file named Index.appcache (the file name can be defined by itself), Index.appcache file contents:

CACHE manifest#version 0.1.0cache:lib/framework7/css/framework7.ios.min.css lib/framework7/css/ FRAMEWORK7.IOS.COLORS.MIN.CSS lib/framework7/js/framework7.min.jsnetwork: *

Description: The cache represents the file to be cached, and the blogger has chosen the FRAMEWORK7 framework's three files to be cached locally, since it does not require a secondary load. The network represents a file that does not need to be cached (the meaning of the * should not be explained), and bloggers use version to pretend that the app revision number controls the file changes.

2. Then in

3. Add Event listener on page page

function (e) {  window.applicationCache.addEventListener (function(e) {
if (window.applicationcache.status==Window.applicationCache.UPDATEREADY) { Window.applicationCache.swapCache (); if (Confirm (' WebApp has new version updated, is it updated?) ') { window.location.reload (); } } Else { console.log (' WebApp is the latest version! '); } false false)

There's nothing in the code that's worth saying, it's short and there's no special meaning, and it's worth noting that:

1). There are two ways to cache files, specifying and adding manifest properties, as long as the page has manifest properties.

2). Cached pages If you have parameters to each cache with parameters, such as index.html is to be cached, then index.html?id=1 will also be added as a different cache, so the multi-parameter page is not recommended to use the AppCache method cache!

[Html5]app offline cache (application cache)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.