javascript 客户端持久化存储
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4278467/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Persistent storage on client side
提问by mihsathe
Is there any way to have some persistent data (like an XML file or so) apart from cookies at client side? I know that's not possible with JavaScript directly. But any other way like Applets or something??
除了客户端的 cookie 之外,还有什么方法可以拥有一些持久数据(如 XML 文件等)?我知道直接使用 JavaScript 是不可能的。但是任何其他方式,如 Applets 之类的?
采纳答案by Charlie Collins
If cookies won't suffice, and you have to support older browsers, then LawnChair might help: http://brian.io/lawnchair/plugins/
如果 cookie 不够用,并且您必须支持旧浏览器,那么 LawnChair 可能会有所帮助:http://brian.io/lawnchair/plugins/
It's like a "Couch" but smaller, get it? Took me a few minutes ;).
它就像一个“沙发”,但更小,明白吗?花了我几分钟;)。
And, it does work for desktop browsers, despite the blurb on the site about mobile-webkit: https://github.com/brianleroux/lawnchair/blob/master/README.md.
而且,它确实适用于桌面浏览器,尽管网站上有关于移动 webkit 的宣传:https: //github.com/brianleroux/lawnchair/blob/master/README.md。
(But, it uses cookies as the adapter to store data for the fallback on those older browsers, most such libraries probably will, if you're not allowed to use cookies for some reason, these types of libraries might not fit the bill.)
(但是,它使用 cookie 作为适配器来存储那些旧浏览器的回退数据,大多数此类库可能会,如果由于某种原因不允许您使用 cookie,这些类型的库可能不符合要求。)
回答by hvgotcodes
回答by cspolton
The latest browsers are supporting HTML5 Local Storage.
最新的浏览器支持 HTML5 本地存储。
If the client doesn't support HTML 5, the Google Gearsplugin allows local storage.
如果客户端不支持 HTML 5,Google Gears插件允许本地存储。
回答by Yeameen
We have been using YUI's local storage wrapperwithout any issue for quite some time. The library automatically uses best available storage option and supports almost all browsers; IE6+, Firefox2.0+, and newer Safari, Chrome and Opera.
我们一直在使用YUI 的本地存储包装器,没有任何问题。该库自动使用最佳可用存储选项并支持几乎所有浏览器;IE6+、Firefox2.0+ 和更新的 Safari、Chrome 和 Opera。
回答by Geo
Html5 local storage is definitely the answer, if you want an example on how to use this feature , check if the browser supports it and how to iterate over the items check this link: http://geoffrey.vandiest.biz/post/2011/04/30/HTML5-Local-Storage.aspx
Html5 本地存储绝对是答案,如果您想要一个关于如何使用此功能的示例,请检查浏览器是否支持它以及如何遍历项目检查此链接:http: //geoffrey.vandest.biz/post/2011 /04/30/HTML5-Local-Storage.aspx
回答by Arthur Weborg
This is an old question, but there are some really nice newer HTML5 technologies for client-side storageworth looking into. you can do it in the javascript now.
这是一个老问题,但有一些非常好的新 HTML5 技术用于客户端存储,值得研究。你现在可以在javascript中做到这一点。
The File-System APIand IndexedDBare definitely worth looking into and should be around to stay!
该文件系统API和索引资料是绝对值得研究的,应该是周围留下来!
To avoid security issues the files you store on the client machines are sandboxed and obfuscated on the client side.
为了避免安全问题,您存储在客户端计算机上的文件在客户端被沙盒化和混淆。
File-System API
文件系统API
File-System APIand for the browsers that don't yet support the File-System API there is a js you can include to get the desired functionality. You can request Temporary or Persistent Storage. The only limitation to your file size with the File-System API is the ammount of free space on the client's harddrive (coupled with the quota you request). Temporary storage within the file-system api will only get you several hundred MB max (a couple GB if you are lucky). I use double digit GBs with PERSISTENT storagefor web applications with little to no issues.
文件系统 API和对于尚不支持文件系统 API 的浏览器,您可以包含一个js 以获得所需的功能。您可以请求临时或持久存储。使用文件系统 API 对文件大小的唯一限制是客户端硬盘驱动器上的可用空间量(加上您请求的配额)。文件系统 api 中的临时存储最多只能为您提供几百 MB(如果幸运的话,可以使用几 GB)。我将两位数的 GBPERSISTENT storage用于 Web 应用程序,几乎没有问题。
IndexedDB
索引数据库
IndexedDBis a more widely browser supported technology. There are more file size limitations for indexedDB, typically you'll be able to get up to a couple hunded MB of space using Quota requests.
IndexedDB是一种更广泛的浏览器支持技术。indexedDB 有更多文件大小限制,通常您可以使用配额请求获得数百 MB 的空间。
回答by kwh
If you're working in Google Chrome, FSO.js wraps the asynchronous FileSystem API for youand is very easy to use.
如果您在 Google Chrome 中工作,FSO.js 为您包装了异步 FileSystem API,并且非常易于使用。
This technology should be supported by other browsers soon.
这项技术应该很快就会被其他浏览器支持。
回答by Emil
I happened to stumble across this Wiki page that lists down a lot of persistent JS stores : https://github.com/bebraw/jswiki/wiki/Storage-libraries
我偶然发现了这个 Wiki 页面,其中列出了许多持久性 JS 存储:https: //github.com/bebraw/jswiki/wiki/Storage-libraries

