Persistent storage in browser - javascript

Currently we are using localStorage as persistent storage in our application. But we noticed that it is prone to data loss. Here is some links which supports this:
HTML5 Local Storage Not Persistent
localStorage data persistence
http://www.sencha.com/forum/showthread.php?132952-localstorage-doesn-t-save-all-data
So now I'm searching for a new solution. It will be good if this solution is supported by chrome/safari at iOS/Android. Could someone suggest something?

if its a website then, there is no means of persistent storage on browser. localstorage, database, cookies, everything is erased if user don't require them. So the only option would be to store the data on the server.
OR
if it is a mobile app (phonegap), then you can use SQL Lite.

Related

How to store More than 5MB data in a Web Storage

I know that local and session storage capacity is 5MB and cookie has 4MB,
If I want to store More than 5MB data in web storage ONLY then what is the alternate solution for this?
Looks like one of the options would be to IndexedDb. Which also has some limitation and they depends on users storage configuration
You can check supported browsers here
One solution that is provided by the browser is IndexedDB.
If the accessibility may be an issue, you might want to check the caniuse page to see what browsers are supported.
I think this is what is used by PouchDB in the background. But you can use it with other backends like localStorage or memory. So it may be good if you are not sure of the quantity of data first, but want to preserve the same API. Also PouchDB can sync with non browser database which is pretty cool for web applications that need to work offline.

Store persistent data without a web server for Chrome Extension

Is there any way to store persistent data for Chrome Extensions without using a web server?
Is Chrome storage persistent? https://developer.chrome.com/apps/storage
I want to avoid the costs of a server, but I also don't think localStorage is good enough because the user can delete it.
In fact, the only persistent data I need to store is the accounts that have logged into the extension on the device itself, so that info might be stored by Google's servers already?
I don`t think there is an non-server way to store extension data without user being able to modify it.
However there are lot of great services that offer free plans for many platforms eg. Heroku

SQLite database with javascript

I have a requirement where I have a postgresql database in a web site.
I want to run my web site in offline mode but the problem is that I have many ajax calls in my website which will not work in offline mode.
So I am considering using sqlLite but I don't know how to configure it, how to write JavaScript code, or even know if the users need to install sqlite in their browser or PC. Can anyone help to overcome this requirement?
I have used some local storage like Indexed DB it will work but that is called sqlLite or not I don't know.
please help
You do not need to work with Sqlite for addressing this, only take a look at following link for how to make web pages available for offline viewing.
If you namely want to use some database it is possible to use SQLite.
Look at https://github.com/kripken/sql.js/
Be care of using SQLite requests in main UI thread. Do not forget to implement workers for SQLite.
I'm pretty sure that you do not need SQLite.
Try using HTML5 LocalStorage API.
https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
The Storage interface of the Web Storage API provides access to the session storage or local storage for a particular domain, allowing you to for example add, modify or delete stored data items.
If you want to manipulate the session storage for a domain, you call Window.sessionStorage method; If you want to manipulate the local storage for a domain, you call Window.localStorage.
https://developer.mozilla.org/en-US/docs/Web/API/Storage

localStorage encryption algorithms

I am using localStorage to store token values and other basic user details for an offline mechanism in an Ionic application. localStorage is not a secure way to store sensitive data. Is there any plugin or any other way to store such data so that it is protected? I am targeting all three platforms, Windows Phone, iOS, and Android.
I came across a cordova plugin called secured storage plugin for this. I hope this should do the trick for you as it keeps the data secured.

How persistent is localStorage?

I'm depending heavily on localStorage for a plugin I'm writing. All the user settings are stored in it. Some settings require the user the write regex'es and they would be sad if their regex rules are gone at some point.
So now I am wondering just how persistent the localStorage is.
From the specs:
User agents should expire data from the local storage areas only for security reasons or when requested to do so by the user.
The above looks like it works just like cookies on the clientside. I.e. when the user clears all browser data (history, cookies, cache etc) the localStorage will also be truncated. Is this assumption correct?
Mozilla implements it like cookies:
DOM Storage can be cleared via "Tools -> Clear Recent History -> Cookies" when Time range is "Everything" (via nsICookieManager::removeAll)
https://developer.mozilla.org/en/DOM/Storage
In DOM Storage it is not possible to specify an expiration period for any of your data. All expiration rules are left up to the user. In the case of Mozilla, most of those rules are inherited from the Cookie-related expiration rules. Because of this you can probably expect most of your DOM Storage data to last at least for a meaningful amount of time.
http://ejohn.org/blog/dom-storage/
Chrome implements it like cache:
LocalStorage is Not Secure Storage
HTML5 local storage saves data unencrypted in string form in the regular browser cache.
Persistence
On disk until deleted by user (delete cache) or by the app
https://developers.google.com/web-toolkit/doc/latest/DevGuideHtml5Storage
As for a "replacement for the Cookie", not entirely
Cookies and local storage really serve difference purposes. Cookies are primarily for reading server-side, LocalStorage can only be read client-side. So the question is, in your app, who needs this data — the client or the server?
Basically, you should not heavily depend on Local Storage.
Local Storage, along with Session Storage, aims to be a replacement of the cookies, defining a more consistent API. There are a few differences from the cookies:
While the cookies are accessible from both client and server side, Web Storage, in general, and Local Storage, in particular, are accessible only from client side.
Enhanced capacity (official for cookies is 4 KB) to more than 5MB per domain (Firefox, Google Chrome, and Opera and 10MB in IE).
So yes, your assumption is correct.
One thing to note about using local storage. It is very browser specific. If you store data with firefox it won't be available in chrome or ie etc. Also as far as clearing cookies and sessions, I've noticed it is also browser specific as to whether or not the local storage is cleared. I'd look into the details a lot if you're really planning on relying on local storage for an app.
Local Storage is designed to be a dependable, persistent store of data on a client. It is not designed as a "better cookie": that function is designed to be met by Session Storage.
From the Dec 2011 Web Storage Spec Candidate Recommendation,
(Local Storage) is designed for storage that spans multiple windows,
and lasts beyond the current session. In particular, Web applications
may wish to store megabytes of user data, such as entire
user-authored documents or a user's mailbox, on the client side for
performance reasons.
As client-side data - it is as persistent as any client side data, within the size limits that the browser implements. Users can delete it at any time, open it up in a text editor and edit etc. - just like ANY client side data.
If you're using localStorage for a iOS app, be very careful. THe latest version of iOS (5.1 off the top of my head) has moved localstorage and localdb data to a part of the cache that is regularly cleared, i.e. not at all persistent. I can't tell yet if this is a bug or a policy change.

Categories