AngularJS + localStorage
Some time ago, I tried to create a couple of module to work with localStorage in an AngularJS app.
Today finally I found the first step to solve this problem.
We should need:
Angular DOMStorage module.
The flow for this is:
Any call over http if checked in localStorage to verify if it's stored.
If the call is not stored, the request goes to the server.
When a response arrives, we store it in localStorage.
If a new request over the same url is made, the interceptor stop the request and cancel the promise, it's handled by responseError and checks if we have the data stored in localStorage, if we have it, the interceptor returns the data from the localStorage.
This approach has many things it should be improved:
Only verifies call with config.url, same url calls with different body are treated as equals.
It never removes items from localStorage.
This is for AngularJS > 1.1.4 non stable versions.
Any comments please let me know, I'll improve this in the next days.
The most important things if this approach is that you don't need to change any other module to make it work. Is one of the best ways I found to handle localStorage.












