The--applicationcache object of the HTML5 series

Source: Internet
Author: User

Applicationcache Main Introduction:

The Applicationcache object implements the HTML5 corresponding to the Web offline function. Let's focus on some of 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 status

The main include the following 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;// Idle State 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 shown 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 checking to manifest that the manifest file does not need to be updated

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 has been downloaded and successfully cached

Upadateready

The meaning of this event means that the cache manifest file has already been downloaded, either by reloading the page to read the cache file or by using method swapcache to switch to the new cache file. Common terms local cache and new version after the prompt

Obsolete

The event is triggered when an access manifest cache file is added to return a HTTP404 error (page not found) or a 410 error (permanent disappearance)

Error

To reach the triggering event, you need to meet one of several situations:

1. Obsolete event has been triggered

2. The manifest file has not changed, but there is a file download failure in the cache file

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 the actual application, we can listen to the event and handle the related business according to the state of the current Applicationcache object.

As shown in the following code:

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


Next, it is worth noting that in the normal development process, while using the Applicationcache local cache, often need to determine the current browser state (online or offline). HTML5 provides a property that determines whether the current browser is online and the code is as follows:

Windowz.navigator.onLine

If 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.