web 存储方式汇总:Cookies,Session, Web SQL; Web Storage(LocalStorage ,SessionStorage),IndexedDB,Application Cache,Cache Storage
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.pngmore ...
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
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的更多相关文章
- js Web存储方式
JSON是数据交互中最常用的一种数据格式. 由于各种语言的语法都不同,在传递数据时,可以将自己语言中的数组.对象等转换为JSON字符串> 传递之后,可以讲JSON字符串,在解析为JSON对象. ...
- HTML5 Web 客户端五种离线存储方式汇总
最近折腾HTML5游戏需要离线存储功能,便把目前可用的几种HTML5存储方式研究了下,基于HT for Web写了个综合的实例,分别利用了Cookie.WebStorage.IndexedDB以及Fi ...
- HTML5新增web存储方式
客户端存储数据的两个对象为: 两个对象在使用方式没有任何区别,唯一的不同点蚀储存数据 的有效时间 ①localStorage - 没有时间限制的数据存储 除非手动删除,否则数据将一直保存在本地文件: ...
- web存储中cookie、session区别
http协议是一种无状态的协议,浏览器对服务器的每一次请求都是独立的.为了使得web能够产生一些动态信息,就需要保存”状态”,而cookie和session机制就是为了解决http协议无状态而产生.c ...
- 【归纳整理】Ajax / JSON / WEB存储 / iframe
Ajax 一.什么是 AJAX ? AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML). AJAX 是一种用于创建快速动态网页 ...
- HTML5: HTML5 Web 存储
ylbtech-HTML5: HTML5 Web 存储 1.返回顶部 1. HTML5 Web 存储 HTML5 web 存储,一个比cookie更好的本地存储方式. 什么是 HTML5 Web 存储 ...
- 一文梳理Web存储,从cookie,WebStorage到IndexedDB
前言 HTTP是无状态的协议,网络早期最大的问题之一是如何管理状态.服务器无法知道两个请求是否来自同一个浏览器.cookie应运而生,开始出现在各大网站,然而随着前端应用复杂度的提高,Cookie 也 ...
- HTML5(七)Web 存储
HTML5 Web 存储 HTML5 web 存储,一个比cookie更好的本地存储方式. 什么是 HTML5 Web 存储? 使用HTML5可以在本地存储用户的浏览数据. 早些时候,本地存储使用的是 ...
- HTML5存储方式
由于之前在参加面试或者笔试的过程中经常会被问到HTML5存储的内容,包括它们之间的区别.特征和应用范围,所以看到一篇介绍不错的文章,把里面的个人觉得适合我的内容按照自己的理解总结如下.方便以后忘记了进 ...
随机推荐
- 导出带有图片的excel
public static void main(String[] args) { try { FileOutputStream out = new FileOutputStream("d:\ ...
- 【Soul源码探秘】插件链实现
引言 插件是 Soul 的灵魂. Soul 使用了插件化设计思想,实现了插件的热插拔,且极易扩展.内置丰富的插件支持,鉴权,限流,熔断,防火墙等等. Soul 是如何实现插件化设计的呢? 一切还得从插 ...
- javascript之Banner图片焦点轮播
这个Banner唯一不好的就是没有前进和后退的button,写过两个版本的banner,这次这个是下面有浮动层的. <!DOCTYPE html><html xmlns=" ...
- 新编日语1234册/重排本/全册 pdf
网上找的资源链接大部分都失效了,无奈之下只好淘宝购买.顺便分享一下吧. 链接: https://pan.baidu.com/s/1v5-osHKrIPzlgpd8yNIP5Q 提取码: kexn
- Salt (cryptography)
Salt (cryptography) Here is an incomplete example of a salt value for storing passwords. This first ...
- 客户端必须在它发送到服务器的所有帧中添加掩码(Mask)
在WebSocket协议中,数据是通过一系列数据帧来进行传输的.为了避免由于网络中介(例如一些拦截代理)或者一些在第10.3节讨论的安全原因,客户端必须在它发送到服务器的所有帧中添加掩码(Mask)( ...
- aio 系列函数是由 POSIX 定义的异步操作接口,可惜的是,Linux 下的 aio 操作,不是真正的操作系统级别支持的,它只是由 GNU libc 库函数在用户空间借由 pthread 方式实现的,而且仅仅针对磁盘类 I/O,套接字 I/O 不支持。
30 | 真正的大杀器:异步I/O探索 https://time.geekbang.org/column/article/150780
- Java 操作Oracle数据库
import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import ...
- Spring框架——事务管理方式搭建一个小的项目
学习Spring框架,通过事务管理的方式搭建一个小的项目,该项目可以查询对数据库中的图书库存数量进行修改. 首先,使用MVC分层的设计模式思想搭建项目目录结构. 此部分代码源码之中都有相关注释,所以尽 ...
- nginx详解、反向代理、负载均衡和LNMP架构
资源池 nginx官方网站:http://nginx.org/ nginx官方文档:http://nginx.org/en/docs/ 本章资源: 点击这里 资源提取码:u2jv 1.nginx简介 ...








