浏览器的本地存储方案
1 IndexedDB exmample
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 , with only Chrome and Firefox having fully usable implementations.
2 WebSQL
is an API that is (and Android and iOS by extension). It provides an asynchronous, transactional interface to . Since 2010, it has been deprecated in favor of IndexedDB.
3 LocalStorage(跨域时ios 10+下退出应用会自动清除,安卓不会)
is a lightweight way to store key-value pairs. The API is very simple, but usage is in many browsers. Plus the API is synchronous, so as we’ll see later, it can block the DOM. Browser support is .
为何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 : 如果是自建app可以设置缓存文件的路径到Documents目录下,如果是第三方app没做这样的保护就没戏了。。这里有一个跨域名(子域名使用的是iframe嵌入页面)写入localStorage的方案:
4 Cookie
不能跨域,包括曾经大量使用的p3p技巧。