Answer the question
In order to leave comments, you need to log in
Maximum application optimization on angularjs + localStorage, what do you think?
Good day to all.
Such a question, can I store a list of names in localStorage and update this array of names if necessary:
localStorage.setItem('users', JSON.stringify(response));
Because in my project lists of names are called more than once via HTTP requests, in this case I just call all the data from localStorage like this:
$scope.names = localStorage.getItem('contact');
I got so carried away by this that I just started to shove all the data into localStorage. Who has an opinion on this example?
1) Is it worth it to do so?
2) What are the negative consequences of this?
3) What can replace localStorage? (I already used pouchD, it's not the same).
4) What can you advise?
Answer the question
In order to leave comments, you need to log in
if they don’t lose their relevance very often, then you can use the “optimistic updates” technique, that is, immediately display the data from the local storage, and only then ask them again from the API, render and write a new list to localStorage, users will have a good experience.
A negative factor in this case may be the "flashing" of the data, if they often change their relevance.
Of the analogs of localStorage, you can use indexDB, it basically has good browser support and is more spread out.
Angular has its own cacheFactory. inside the factory:
var httpFactory = {},
cache = $cacheFactory.get('$http');
httpFactory.getInterest = function () {
return getWithCache('ref/user-interest')
};
function getWithCache (url) {
var mycache = httpFactory.getCache(baseUrl+url);
if(mycache) {
const _mycache = angular.copy(mycache);
var deferred = $q.defer();
deferred.resolve({data:JSON.parse(_mycache[1])});
return deferred.promise
}
else return $http.get(baseUrl+url, {cache: true})
}
Especially for you there is such a thing: https://pouchdb.com/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question