The--applicationcache object of the HTML5 series

Source: Internet
Author: User

Applicationcache Main Brief Introduction:

The Applicationcache object implements HTML5 the corresponding web offline function. Let us explain the main functions and methods of the Applicationcache object.

The Applicationcache object records the various states and events of the local cache. The state of the cache can be obtained through window.applicationCache.status and its state

The main inclusions are as follows 6 kinds:

<span style= "Font-family:microsoft yahei;font-size:12px;" >interface applicationcache:eventtarget{const unsigned short uncached=0;//not cached const unsigned short idle=1;// Spare Status const unsigned short checking=2;//check in const unsigned short downloading=3;//Download const unsigned short updateready=4;// Update ready in const unsigned short OBSOLETE =5;//expiration status readonly attribute unsigned short status;} </span>

The events for the Applicationcache cache object are seen in the following table:

Event name

Description

Checking

When the user agent checks for updates, or the first time the manifest manifest is downloaded, it is often the first event to be triggered

Noupdate

This event is triggered when the manifest file does not need to be updated in the check to manifest

Downloading

This event is triggered the first time the manifest manifest file is downloaded or updated

Progress

This event is similar to downloading, but the downloading event is triggered only once. Progress events are triggered periodically during the download of the manifest file

Cached

This event is triggered when the manifest manifest file finishes downloading and successfully caching

Upadateready

The meaning of this event means that the cache manifest file has been downloaded and can be read from another load of the page, or switched to a new cache file via method Swapcache. Tips for frequently used local cache with new version number

Obsolete

Increased access to the manifest cache file to return a HTTP404 error (page not found) or 410 error (permanent disappearance) When the event is triggered

Error

To trigger this event, you need to meet one of several scenarios:

1. Obsolete event has been triggered

2, manifest file has not changed, but there is a file download in the cache file failed

3. A fatal error occurred while getting the manifest resource file.

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


In real-world applications, we are able to listen to events and handle related businesses based on the state of the current Applicationcache object.

For example, the following code sees:

<span style= "Font-family:microsoft Yahei;" >applicationcache.addeventlistener (' Updateready ', function () {///resource file download, ability to add business functions in this section});</span>


Next, it is worth noting that in the normal development process, when using the Applicationcache local cache at the same time, often need to infer the current browser state (online or offline). HTML5 provides a property that infers whether the current browser is online, such as the following code:

Windowz.navigator.onLine

Assuming that ture is returned, the current browser online and false indicates the current browser offline

--applicationcache objects for the HTML5 series

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.