HTML5 series -- applicationCache object

Source: Internet
Author: User

HTML5 series -- applicationCache object

ApplicationCache Overview:

The applicationCache object implements the offline WEB functions corresponding to HTML5. The following describes some of the main functions and methods of the applicationCache object.

The applicationCache OBJECT records various statuses and events in the local cache. The cache status can be obtained through window. applicationCache. status.

It mainly includes the following 6 types:

Interface ApplicationCache: EventTarget {const unsigned short UNCACHED = 0; // The UNCACHED const unsigned short IDLE = 1; // The IDLE State const unsigned short CHECKING = 2; // check const unsigned short DOWNLOADING = 3; // In the download, const unsigned short UPDATEREADY = 4; // In the update preparation, const unsigned short OBSOLETE = 5; // expired status readonly attribute unsigned short status ;}

The following table lists the events of cached objects in applicationCache:

Event name

Description

Checking

When the user agent checks for updates or downloads the manifest list for the first time, it is often the first trigger event.

Noupdate

This event is triggered when the configuration file in Manifest does not need to be updated.

Downloading

This event is triggered when the manifest configuration file is downloaded or updated for the first time.

SS

This event is similar to downloading, but the downloading event is only triggered once. The SS event is periodically triggered during the download of the list file.

Cached

This event is triggered after the manifest file is downloaded and cached successfully.

Upadateready

The meaning of this event indicates that the cache list file has been downloaded. You can re-load the page to read the cache file or switch to the new cache file through swapCache. Common Terms: local cache and prompt after the new version

Obsolete

This event is triggered when an HTTP404 error (page not found) or 410 error (permanent disappearance) is returned when a file is added to the manifest cache file.

Error

To trigger this event, you must meet one of the following conditions:

1. the obsolete event has been triggered.

2. The manifest file has not changed, but the file in the cache file fails to be downloaded.

3. a fatal error occurs when obtaining the manifest resource file.

4. When updating the local cache, the manifest file is changed again.


In practical applications, we can use event monitoring to process related services based on the status of the current applicationCache object.

The following code is used:

ApplicationCache. addEventListener ('updateready', function () {// The resource file is being downloaded. You can add business functions in this part });


Next, it is worth noting that during normal development, while using the applicationCache local cache, it is often necessary to determine the current browser status (online or offline ). HTML5 provides an attribute to determine whether the current browser is online. The Code is as follows:

Windowz. navigator. onLine

If true is returned, the current browser is online. If false is returned, the current browser is offline.

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.