I'm writting an application using angular and spring. It has to be able to work offline. After doing some research I found that application cache is the best way to go since I need to cache all the .css and .js files. The problem is that I can't get the data returned by spring and asked by the $resource object to be cached. When I turn off the server, static data are cached but I get a "GET error" in chrome's console about the .json he can't retrieve.
angular.module('MonService', ['ngResource']).
factory('Projet', function($resource){
return $resource('json/accueil');
});
I've tried something such as saving the response manually in a .json file then caching this file as well and use it as the source for the $resource but it seems long and complicated...
Or using localstorage, something like :
var cache, AmettreDansCache;
donne = {};
cache= window.localStorage.getItem('projets');
if (!cache) {
AmettreDansCache= $resource('json/accueil');
window.localStorage.setItem('projets', JSON.stringify(AmettreDansCache));
return AmettreDansCache
}
else{
return angular.extend(donne, JSON.parse(cache));
}
i don't think this is working, anyway what's the way to do it using application cache only ?
cacheoption on the $resource object? docs.angularjs.org/api/ngResource.$resource