1

1

1

web 存储方式汇总:

旧的方式:

Cookies;

Session;

Web SQL;

新的方式 HTML5 :

Web Storage(LocalStorage ,SessionStorage);

IndexedDB;

Application Cache;

Cache Storage ?

1

1

1

Cookies

https://www.w3.org/TR/csp-cookies/

Content Security Policy: Cookie Controls

W3C First Public Working Draft, 15 December 2015

https://html.spec.whatwg.org/multipage/webstorage.html#storage

demo:

document.cookie = "key=value";
document.cookie = "key=value; domain=example.com"; document.cookie = "key=value; secure";
document.cookie = "key=value";
document.cookie = "key=value; domain=example.com; secure";

1

Session

https://html.spec.whatwg.org/multipage/browsers.html#dom-history-pushstate

HTML

Living Standard — Last Updated 1 September 2016

https://html.spec.whatwg.org/multipage/webstorage.html#storage

https://html.spec.whatwg.org/multipage/indices.html#event-pageshow

https://www.w3.org/TR/WD-session-id

Session Identification URI

W3C Working Draft WD-session-id-960221

demo:

//session demo ???

1

Web SQL

https://www.w3.org/TR/webdatabase/

Web SQL Database

W3C Working Group Note 18 November 2010

Beware.

This specification is no longer in active maintenance and the Web Applications Working Group does not intend to maintain it further.

demo:

function prepareDatabase(ready, error) {
return openDatabase('documents', '1.0', 'Offline document storage', 5*1024*1024, function (db) {
db.changeVersion('', '1.0', function (t) {
t.executeSql('CREATE TABLE docids (id, name)');
}, error);
});
} function showDocCount(db, span) {
db.readTransaction(function (t) {
t.executeSql('SELECT COUNT(*) AS c FROM docids', [], function (t, r) {
span.textContent = r.rows[0].c;
}, function (t, e) {
// couldn't read database
span.textContent = '(unknown: ' + e.message + ')';
});
});
} prepareDatabase(function(db) {
// got database
var span = document.getElementById('doc-count');
showDocCount(db, span);
}, function (e) {
// error getting database
alert(e.message);
});

1

1

out of date: ...

VS

new & fashion & popular:  HTML5

1

1

Web Storage  (LocalStorage ,SessionStorage)

https://www.w3.org/TR/webstorage/

Web Storage (Second Edition)

W3C Recommendation 19 April 2016

https://html.spec.whatwg.org/multipage/webstorage.html#storage

(LocalStorage)

demo:

function lStorage(){
//localStorage
var ls = localStorage.getItem("ls");
if (ls === "localStorage") {
console.log("localStorage.getItem success!");
} else {
ls = localStorage.setItem("ls","localStorage");
console.log("localStorage.setItem success!");
}
};
lStorage();

(SessionStorage)

demo:

function sStorage(){
//sessionStorage
var ss = sessionStorage.getItem("ss");
if (ss === "sessionStorage" ) {
console.log("sessionStorage.getItem success!");
} else {
ss = sessionStorage.setItem("ss","sessionStorage");
console.log("sessionStorage.setItem success!");
}
};
sStorage();

1

IndexedDB

https://www.w3.org/TR/IndexedDB/

Indexed Database API

W3C Recommendation 08 January 2015

demo:

var request = indexedDB.open("library");

request.onupgradeneeded = function() {
// The database did not previously exist, so create object stores and indexes.
var db = request.result;
var store = db.createObjectStore("books", {keyPath: "isbn"});
var titleIndex = store.createIndex("by_title", "title", {unique: true});
var authorIndex = store.createIndex("by_author", "author"); // Populate with initial data.
store.put({title: "Quarry Memories", author: "Fred", isbn: 123456});
store.put({title: "Water Buffaloes", author: "Fred", isbn: 234567});
store.put({title: "Bedrock Nights", author: "Barney", isbn: 345678});
}; request.onsuccess = function() {
db = request.result;
};

1

Application cache 

https://www.w3.org/TR/html5/browsers.html#application-cache

Offline web applications

https://html.spec.whatwg.org/multipage/browsers.html#offline

demo:

CACHE MANIFEST

/main/home
/main/app.js
/settings/home
/settings/app.js
http://img.example.com/logo.png
http://img.example.com/check.png
http://img.example.com/cross.png

more ...

https://www.w3.org/TR/html5/browsers.html#offline

5.7 Offline Web applications

https://www.w3.org/TR/html5/browsers.html#appcache

5.7.2 Application caches

https://www.w3.org/TR/html5/browsers.html#application-cache-api

An application cache is a set of cached resources consisting of:

https://www.w3.org/TR/html5/browsers.html#application-cache

5.7.9 Application cache API

https://www.w3.org/TR/html5/webappapis.html#webappapis

6 Web application APIs

1

Cache Storage ???

http://caniuse.com/#search=Cache%20Storage

0 results found.

https://www.w3.org/TR/offline-webapps/

Offline Web Applications

W3C Working Group Note 30 May 2008

1

1

1

1

1

1

1

1

1

1

1

w3c others

https://www.w3.org/TR/XMLHttpRequest/

XMLHttpRequest Level 1

W3C Working Draft 30 January 2014

https://www.w3.org/TR/websockets/

The WebSocket API

W3C Candidate Recommendation 20 September 2012

https://www.w3.org/TR/mobile-bp/

Mobile Web Best Practices 1.0

Basic Guidelines

W3C Recommendation 29 July 2008

https://www.w3.org/TR/cors/

Cross-Origin Resource Sharing

W3C Recommendation 16 January 2014

1

1

1

web 存储方式汇总:Cookies,Session, Web SQL; Web Storage(LocalStorage ,SessionStorage),IndexedDB,Application Cache,Cache Storage的更多相关文章

  1. js Web存储方式

    JSON是数据交互中最常用的一种数据格式. 由于各种语言的语法都不同,在传递数据时,可以将自己语言中的数组.对象等转换为JSON字符串> 传递之后,可以讲JSON字符串,在解析为JSON对象. ...

  2. HTML5 Web 客户端五种离线存储方式汇总

    最近折腾HTML5游戏需要离线存储功能,便把目前可用的几种HTML5存储方式研究了下,基于HT for Web写了个综合的实例,分别利用了Cookie.WebStorage.IndexedDB以及Fi ...

  3. HTML5新增web存储方式

    客户端存储数据的两个对象为: 两个对象在使用方式没有任何区别,唯一的不同点蚀储存数据 的有效时间 ①localStorage - 没有时间限制的数据存储 除非手动删除,否则数据将一直保存在本地文件: ...

  4. web存储中cookie、session区别

    http协议是一种无状态的协议,浏览器对服务器的每一次请求都是独立的.为了使得web能够产生一些动态信息,就需要保存”状态”,而cookie和session机制就是为了解决http协议无状态而产生.c ...

  5. 【归纳整理】Ajax / JSON / WEB存储 / iframe

      Ajax 一.什么是 AJAX ? AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML). AJAX 是一种用于创建快速动态网页 ...

  6. HTML5: HTML5 Web 存储

    ylbtech-HTML5: HTML5 Web 存储 1.返回顶部 1. HTML5 Web 存储 HTML5 web 存储,一个比cookie更好的本地存储方式. 什么是 HTML5 Web 存储 ...

  7. 一文梳理Web存储,从cookie,WebStorage到IndexedDB

    前言 HTTP是无状态的协议,网络早期最大的问题之一是如何管理状态.服务器无法知道两个请求是否来自同一个浏览器.cookie应运而生,开始出现在各大网站,然而随着前端应用复杂度的提高,Cookie 也 ...

  8. HTML5(七)Web 存储

    HTML5 Web 存储 HTML5 web 存储,一个比cookie更好的本地存储方式. 什么是 HTML5 Web 存储? 使用HTML5可以在本地存储用户的浏览数据. 早些时候,本地存储使用的是 ...

  9. HTML5存储方式

    由于之前在参加面试或者笔试的过程中经常会被问到HTML5存储的内容,包括它们之间的区别.特征和应用范围,所以看到一篇介绍不错的文章,把里面的个人觉得适合我的内容按照自己的理解总结如下.方便以后忘记了进 ...

随机推荐

  1. Python格式化处理json数据的方式

    1.问题 在遇到json数据的过程中,我们经常需要获取json数据中某个值的操作,如果是用get方法去取比较繁琐,接下来介绍两种方式来取值. 2.jsonpath来格式化处理json数据 2.1介绍 ...

  2. Java 复习整理day03

    变量或者是常量, 只能用来存储一个数据, 例如: 存储一个整数, 小数或者字符串等. 如果需要同时存储多个同类型的数据, 用变量或者常量来实现的话, 非常的繁琐. 针对于 这种情况, 我们就可以通过数 ...

  3. 肝了一个半月的 Java 项目快速开发脚手架:Chewing

    前言 闲来无事,整一个 Java 项目快速开发脚手架. 正文 一.简介 Chewing 是一个简单的 Java 项目快速开发脚手架.既适合需要开发小型项目的小伙伴使用,也适合刚入门的新手用来学习一些常 ...

  4. Object类的常见方法总结

    ♧ Object类是比较特殊的类,它是所有类的父类.主要提供了11个方法(JDK 1.8为例): /** * native方法,用于返回当前运行时对象的Class对象,使用final关键字修饰,子类不 ...

  5. 【机制】js的闭包、执行上下文、作用域链

    1.从闭包说起 什么是闭包 一个函数和对其周围状态(词法环境)的引用捆绑在一起,这样的组合就是闭包. 也就是说,闭包让你可以在一个内层函数中访问到其外层函数的作用域. 在 JavaScript 中,每 ...

  6. 代码审计学习01-in_array() 函数缺陷

    一.开始代码审计之旅 01 从今天起,学习代码审计了,这篇文章就叫代码审计01吧,题目来自 PHP SECURITY CALENDAR 2017 的第一题,结合 红日安全 写的文章,开始吧. 二.先看 ...

  7. [POJ1985] Cow Marathon 「树的直径」

    >传送门< 题意:求树的直径 思路:就是道模板题,两遍dfs就求出来了 Code #include <cstdio> #include <iostream> #in ...

  8. 1. Machine Learning - Introduction

    Speaker: Andrew Ng   1. Introduction 1.A comptuter program is said to learn from experience E with r ...

  9. zoj2112 Dynamic Rankings (主席树 || 树套树)

    The Company Dynamic Rankings has developed a new kind of computer that is no longer satisfied with t ...

  10. 关于最小生成树 Kruskal 和 Prim 的简述(图论)

    模版题为[poj 1287]Networking. 题意我就不说了,我就想简单讲一下Kruskal和Prim算法.卡Kruskal的题似乎几乎为0.(●-`o´-)ノ 假设有一个N个点的连通图,有M条 ...