Is there a way to retain local storage in mobile browsers? - reactjs

This question is more theoretical than practical, hence i do not have any code to show for it.I using a PWA application in mobiles and I'm storing data in the local storage. so far so good. But if I force clear (remove the application from running in the background), I believe the local storage gets cleared, which is not ideal. Is there any way to prevent the os or browser from automatically clearing the local storage?

Some of the useful links which helps you understand the functionalities of local storage https://developer.chrome.com/apps/storage
Instead use Service worker as here

Related

Does clearing browser cache mean clearing chrome.storage extension data?

I'm considering hiring a developer from upwork.com to build my chrome extension. He was saying he would need to build it using local storage, but I questioned him and asked why he couldn't use the chrome.storage API. His response was that if the user clears the browser cache, it would clear everything saved in the extension. That didn't seem right to me but I wanted to ask you all.
No, even after clearing ALL browser data and cache if you are using chrome.storage API any data stored in that manner will still be present.
Unless you explicitly clear the extensions storage by command it will not be cleared.
Extensions in Google Chrome will not be removed or preferences changed/cleared.
You are right that this will also depend on where your extension saves its preferences, for example, extensions may allow you to sign in and save your data in the cloud - whereas other may not. There are multiple ways to store this data, ask why an extension developer cannot develop a robust extension?

Developing application that represents same screen across multiple browser windows of same machine using AngularJS

I have to create one application that represents the same screen(sharing the state of the view/screen) across multiple browser windows of same machine using AngularJS.
During my analysis I found perhaps AngularJS is not the best technology to handle such scenarios, please find below my thoughts:
If I open the same application in second window of the browser after
opening it in the first one, I need to copy the full
state(rootScope/scope/services) to other window
If user performs some action in one window I need to update the other screen/window accordingly for which I need to use web sockets
Complexity of scope digest cycles execution
Please suggest.
I faced kinda the same scenario while working on chat sessions where the user can open multiple chat windows (as popup windows) while the parent site is open. I used local storage for handling some of its scenarios. I used angular-local-storage for this.
Note: Make sure you are handling (deleting/updating/adding) the data properly while storing it in local storage of browser. Graceful execution is the key or else you'll end up with many bugs.
Hope it helps !

Does AngularJS $templateCache store data on local hardrive

I'm building an application that presents sensitive patient information.
One of my routes shows presents an HTML fragment received from the server that contains an image of a patient document.
I need to ensure that that document is not accessible on disk after the page is closed
That would be a really big issue if it was left there.
I noticed that the route was caching and I had to remove it from $templateCache to detect changes. Is that just cached in memory or is it local hdd?
A broader question might be: does Angular cache anything on persistent storage beyond what the browser already does according to HTTP cache control headers?
This really depends on the abstraction level you look at:
A Javascript app cannot write arbitrary files to the disk - there is the well-known browser sandbox, and this also applies to angular.js apps. So, if you are not specifically using the Browser offline APIs such as LocalStorage, Cookies, ... in your own code, there will be "just" the usual browser cache. So you should be fine.
Caveat 1: Sometimes it seems to be quite hard to control the browser caches, there are multiple ways browsers cache things as you already mentioned. They can usually be by http headers. So if you configure your HTTP headers very carefully you should be fine.
Caveat 2: There are multiple ways operating systems cache things and they may or may not save some of these caches to disk (as a simple example consider the windows hibernation file: there is probably a copy of your image in there when you had it open in your browser upon hibernation.). This cannot be controlled by a browser app - but for most applications it does not really matter.

How to set "cache dependency" to local storage

We are using local storage module from angularjs.
https://github.com/grevory/angular-local-storage
Now can anybody suggest how we can set a cache dependency at client side, so that when data changes in the server the local storage is invalidated(forcing to fetch data afresh from server).
Right now in test environment, we had to ask the testers to clear browser cache each time there is a release. Cant move with this approach in production.
Thanks for helping.
Setup a version number in your app, and store it in the local storage when the user visits.
When the app is initialised, compare the local storage version with the App.version.
If it's different, clear local storage and re-render, reload, re-initialise or whatever you need to do for your app.
To handle the situation where a user has used your app before you implemented this behaviour, simply ensure it also clears local storage if it cannot find a version key in local storage to begin with.
Just a couple of further notes, relating to the comments.
I've had issues in the past with local storage due to different things happening. Part 3 goes beyond the scope of the question but is worth mentioning for completeness.
A new release: the application source code has changed, and the data it's storing is structured differently. Perhaps it's now JSON.stringified, for example. Or perhaps we were expecting a string and now we get an integer, which might break something with strict type checking.
This is solved using the approach described above. The app has changed, so the app has a new version, and it knows it cannot trust the data retrieved from local storage for a different version.
The problem you describe: the data on the server has been updated and the app's locally stored copy is out of date.
How do we tell the app that things have changed? Periodically request some token from the server, perhaps a timestamp, that we can compare to see if there was a change since we last accessed the data. This question talks about a number of different ways to do this.
The JavaScript itself has changed: we have a minified production build and now there is a new one, but the user still has the old build cached. This is a problem when the server is expecting different requests to what it will now receive from the new build.
The simple solution here is to tack a version number of some kind onto the end of the resource URL, so that the browser requests application.min.js?v=2 instead of application.min.js?v=1.

Is Silverlight isolated storage treated as permanent, or as a cache?

How persistent is isolated storage - does Silverlight treat it like a cache, deleting items when it needs more space, or only when the user or application request it?
There also seems to be a wide variety of means to identify isolated storage - machine, application, domain, .... What I'm having trouble with is how these all relate to the user. Is it possible, and if so how, to create and later retrieve an isolated storage file with the following properties:
The same file is used, regardless of which Windows user is logged in
The same file is used, regardless of the assembly version (updates to the xap). Instead the url would remain constant. This would have to work even offline (out of browser).
Basically I want the isolated storage to persist across application updates, and over different users logging in.
It is fairly permanent. The user could delete it if they really wanted too, but they would have to go out of their way to do so.
Here is the MSDN documentation for Isolated Storage.
IsolatedStorageFile in Silverlight a couple of statics that let you choose where you want to scope the storage:
GetUserStoreForApplication
GetUserStoreForSite
The "MachineStore" options are not available in Silverlight, there are just "Application" and "Site". Both are scoped by the user..since the files are stored under the user's AppData on Windows. Apps in-browser and out-of-browser share the same Isolated Storage stores.
[edit..I missed part of your question the first time]: The Isolated Storage stores are not part of the browser cache, so they are not cleared when the browser cache is cleared. As a developer, you can delete things programmatically. As a user, you can use the Silverlight configuration UI (i.e. the right-click menu) to manage the stores - it's called "Application Storage" to the user. Finally, an intrepid user can locate the files on disk and delete them manually...they are hidden so they won't show up in a normal search, but a determined user can still find them.

Resources