浏览器的本地存储方案
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技巧。