Home > Article > Web Front-end > Detailed explanation of several examples of html5 storing data on the client
HTML5 introduces application cache, which means that web applications can be cached and can be used even without a network.
The application cache has three characteristics
Offline browsing
Cached resources Faster loading
Reduce server load, the browser will only download updated or changed resources from the server
Each page with a specified manifest will be cached when the user accesses it. If the manifest attribute is not specified, the page will not be cached (unless it is specified directly in the manifest file).
The recommended file extension for manifest files is: ".appcache".
<!DOCTYPE HTML> <html manifest="demo.appcache"> <body> The content of the document...... </body> </html>
Manifest files are simple text files that tell the browser what is cached (and what is not cached).
Manifest files can be divided into three sections:
CACHE MANIFEST - Files listed under this heading will be cached after the first download
NETWORK - The files listed under this heading require a connection to the server and will not be cached
CACHE MANIFEST # 2012-02-21 v1.0.0 /theme.css /logo.gif /main.js NETWORK: login.asp FALLBACK: /html5/ /404.html2.localStorage & sessionStorage HTML5 provides two new ways to store data on the client side:
Methods of localStorage and sessionStorage:
Purpose: Store value into the key field
Usage: .setItem(key, value)
Code example:
sessionStorage.setItem("key", "value"); localStorage.setItem("site", "js8.in");getItem gets value
Usage: Get the locally stored value of the specified key
Usage: .getItem(key)
Code example:
var value = sessionStorage.getItem("key"); var site = localStorage.getItem("site");removeItemDelete key
Usage: Delete the specified key Locally stored value
Usage: .removeItem(key)
Code example:
sessionStorage.removeItem("key"); localStorage.removeItem("site");clear clear all key/value
Usage: clear all Key/value
Usage: .clear()
sessionStorage is not a persistent storage and will be cleared after the browser is closed. LocalStorage is used for persistent local storage. Unless the data is actively deleted, the data will never expire.
3.indexDBindexDB is a lightweight NOSQL database. It is more efficient than web sql (sqlite), including indexing, transaction processing and robust query functions. Its features include:The above is the detailed content of Detailed explanation of several examples of html5 storing data on the client. For more information, please follow other related articles on the PHP Chinese website!