浏览器的本地存储方案及跨域

浏览器的本地存储方案

 

1 IndexedDB exmample

https://www.codeproject.com/Articles/325135/Getting-Started-with-IndexedDB

https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB

IndexedDB is the successor to both LocalStorage and WebSQL, designed to replace them as the “one true” browser database. It exposes an asynchronous API that supposedly avoids blocking the DOM, but as we’ll see below, it doesn’t necessarily live up to the hype. Browser support is extremely spotty, with only Chrome and Firefox having fully usable implementations.

2 WebSQL

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

WebSQL is an API that is only supported in Chrome and Safari (and Android and iOS by extension). It provides an asynchronous, transactional interface to SQLite. Since 2010, it has been deprecated in favor of IndexedDB.

3 LocalStorage(跨域时ios 10+下退出应用会自动清除,安卓不会)

https://developer.mozilla.org/en-US/docs/Web/API/Storage/LocalStorage

LocalStorage is a lightweight way to store key-value pairs. The API is very simple, but usage is capped at 5MB in many browsers. Plus the API is synchronous, so as we’ll see later, it can block the DOM. Browser support is very good.

为何LocalStorage会在iOS里被清除的原因:

WebKit data (localstorage or local SQLite) are now stored in Library/ Caches folder (instead of Library/WebKit folder). This is a big problem for all apps using UIWebView and storing user data, because they will no longer be backed up and may be deleted. There are a lot of apps using localstorage or SQLite as a critical feature.

The SQLite database gets deleted because the database is saved in a location on the filesystem which Apple does not consider to contain persistent data.

The WebKit data are stored in Library/Caches folder, and can be 
deleted

source from : https://issues.apache.org/jira/browse/CB-330 如果是自建app可以设置缓存文件的路径到Documents目录下,如果是第三方app没做这样的保护就没戏了。苹果关于存储的说明

这里有一个跨域名(子域名使用的是iframe嵌入页面)写入localStorage的方案:

https://github.com/mattiaocchiuto/iframe-localstorage

4 Cookie

不能跨域,包括曾经大量使用的p3p技巧。

5 the File API

6 window.name

7 SessionStorage

8 the Service Worker cache

转载于:https://my.oschina.net/swingcoder/blog/1586976

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值