Table of Contents
1.Application Cache" >1.Application Cache
The method of use is to Add a manifest attribute to the html tag
Home Web Front-end H5 Tutorial Detailed explanation of several examples of html5 storing data on the client

Detailed explanation of several examples of html5 storing data on the client

May 30, 2017 am 10:40 AM

1.Application Cache

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

The method of use is to Add a manifest attribute to the html tag

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>
Copy after login

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

  • ##FALLBACK - The files listed under this heading require a connection to the page Fallback page when inaccessible (such as 404 page)

A complete manifest file


CACHE MANIFEST  
# 2012-02-21 v1.0.0
/theme.css
/logo.gif
/main.js
NETWORK:
login.asp
FALLBACK:
/html5/ /404.html
Copy after login
2.localStorage & sessionStorage

HTML5 provides two new ways to store data on the client side:

  • localStorage - data storage without time limits

  • sessionStorage - Data storage for a session

Before, these were all done by cookies. But cookies are not suitable for storing large amounts of data because they are passed with each request to the server, which makes cookies slow and inefficient.

Both localStorage and sessionStorage have the same operation methods, such as setItem(), getItem() and removeItem(), etc.

Methods of localStorage and sessionStorage:

setItem stores value

Purpose: Store value into the key field
Usage: .setItem(key, value)
Code example:


sessionStorage.setItem("key", "value");
localStorage.setItem("site", "js8.in");
Copy after login
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");
Copy after login
removeItemDelete key

Usage: Delete the specified key Locally stored value
Usage: .removeItem(key)
Code example:


sessionStorage.removeItem("key"); 
localStorage.removeItem("site");
Copy after login
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.indexDB

indexDB is a lightweight NOSQL database. It is more efficient than web sql (sqlite), including indexing, transaction processing and robust query functions.

Its features include:

  • A website may have one or more IndexedDB databases, and each database must have a unique name.

  • A database can contain one or more object stores. An object store (uniquely identified by a name) is a collection of records. Each record has a key and a value. The value is an object that can have one or more properties. Keys may be based on a key generator, derived from a key path, or set explicitly. A key generator that automatically generates unique consecutive positive integers. The key path defines the path to the key value. It can be a single JavaScript identifier or multiple identifiers separated by periods. (Somewhat like the characteristics of a column database)

  • In IndexedDB, almost all operations use the command->request->result method. For example, query a record, return a request, and get the query result in the result of the request. Another example is opening a database, returning a request, and getting the returned database reference in the result of the request.

  • indexedDB needs to be placed on the web server before it can run.

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

See all articles