September 2 = 446-450

Source: Internet
Author: User

16.2.3 online status judgment

To determine the browser's online status, HTML5 provides two methods to check whether the browser is online.

Navigator. Online attribute: the navigator. Online attribute returns whether the current status is online. If true is returned, it indicates online. If false is returned, it indicates offline. When the network changes,

The value of navigator. Online also changes. Developers can obtain the network status by reading its value.

Onlne/ofline events: If a developer needs to be notified immediately when the network status changes, the online/offline events provided by html5. Body element during online/offline status Switching

The online/Offline Event on will be triggered and bubble along document. Body, document, and window. Therefore, developers can detect network status changes through their online/offline events.

 

16.2.4 applicationcache object

After the Offline Application is enabled, JavaScript can use applicationcache to control the offline cache. The applicationcache Interface contains a status attribute,

This attribute may return the following status values:

Uncached: the host of the applicationcache object does not enable the Offline Application function.

Idle: idle.

Checking: checking the difference between the manifest file cached locally and the manifest file on the server.

Downloading: downloading the data to be cached.

Updateready: the file to be cached has been downloaded from the server, but the local cache has not been updated.

Obsolete: the cache has expired.

The applicationcache interface defines the following two common methods.

Void Update (): This method forcibly checks whether the manifest file on the server has been updated.

Void swapcache (): This method is used to manually update the local cache. It can only be called when the updateready event of the applicationcache object is triggered.

 

16.2.5 Offline Application events and monitoring

From the above introduction to applicationcache, we can see that a series of events are continuously triggered during the use of applicationcache.

The following is a brief introduction to Offline Application events. When a visitor visits a specified website for the first time, such as http: // localhost: 8888/cacheqs/index.html, the complete process is as follows.

(1) The browser requests the http: // localhost: 8888/cacheqs/index.html page.

(2)server returns to the index.html page.

(3) the browser checks whether the manifes attribute is specified on the page. If this attribute is not specified, no subsequent behavior will be performed. If this attribute is specified, the checking event is triggered, check the specified manifest attribute

Whether the manifest file exists. If the file does not exist, an error event is triggered. Step 1 and subsequent steps are not specified.

(4) index.html page, request other resources caused by this page, such as JavaScript files and images.

(5) The server returns all requested resources.

(6) The browser starts to process manifest files. Refresh to the server and request all resources listed in the manifestfile to include the index.html page. Although these resources have been downloaded before, you need to download them again.

(7) The server returns all resources that require local cache.

(8) The browser starts to download resources that need to be locally cached. The ondownloading event is triggered when the download starts. The onprogress event is continuously triggered during the download process to help developers understand the download progress.

(9) The oncache event is triggered after the download is complete, indicating that the server cache is complete.

When the browser accesses the http: // localhost: 8888/cacheqs/index.html page again ~ The five steps are exactly the same. Next, the browser checks whether the newly downloaded manifest file has changed with the locally cached manifest file:

If the manifest does not change, the onnoupdate event is triggered without subsequent steps.

If the manifest file changes, continue with steps 7th and 8 above. After downloading all files to be cached locally, the browser triggers the onupdateready event instead of the oncached event.

September 2 = 446-450

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.