简体   繁体   English

在本地为Web存储数据的最佳实践

[英]Best practice to store data locally for web

I'm working on some web application and we need to store number of javascript objects in local storage. 我正在开发一些Web应用程序,我们需要在本地存储中存储多个javascript对象。 Until now we did it using cookies but we want to use one of HTML5 storage solutions because cookies data is send to server on each server call and it is a waste of resources and also it's size is very limited. 到目前为止,我们使用cookie实现了它,但我们想使用HTML5存储解决方案之一,因为cookie数据在每次服务器调用时都会发送到服务器,这是浪费资源,而且它的大小非常有限。 The data should be stored permanently, I mean it should be available after closing the browser and opening it again. 数据应该永久存储,我的意思是它应该在关闭浏览器并再次打开后可用。

What is the best practice to do this? 这样做的最佳做法是什么? Is there any way to store objects in local storage. 有没有办法将对象存储在本地存储中。 Thanks for the assistance 谢谢你的帮助

In my current project I'm using PouchDB library ( http://pouchdb.com/ ). 在我目前的项目中,我正在使用PouchDB库( http://pouchdb.com/ )。 It is a lightweight javascript database which can store data locally in browser (string, int, object etc). 它是一个轻量级的javascript数据库,可以在浏览器本地存储数据(字符串,整数,对象等)。 All stored data are still available after browser restart. 浏览器重启后,所有存储的数据仍然可用。

You should use it with some JS framework, in my case it is AngularJS (very simple integration). 您应该将它与一些JS框架一起使用,在我的例子中它是AngularJS(非常简单的集成)。

Have a look at this link: http://slides.html5rocks.com/#web-storage 看看这个链接: http//slides.html5rocks.com/#web-storage

It sounds like HTML5's Local Storage is definitely a great option for you. 这听起来像HTML5的本地存储绝对是一个很好的选择。 That presentation has a lot of great info in that should help you decide on the best form of storage. 该演示文稿有很多很好的信息,可以帮助您确定最佳存储形式。

IndexedDb is a good option for storing javascript objects. IndexedDb是存储javascript对象的好选择。

I strongly recommend you to read this -> https://developer.mozilla.org/en-US/docs/IndexedDB 我强烈建议你阅读这篇文章 - > https://developer.mozilla.org/en-US/docs/IndexedDB

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM