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
This attribute may return the following status values:
Uncached: the host of the applicationcache object does not enable the Offline Application function.
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.
(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