json - AngularJS, $resource and application cache -


i'm writting application using angular , spring. has able work offline. after doing research found application cache best way go since need cache .css , .js files. problem can't data returned spring , asked $resource object cached. when turn off server, static data cached "get error" in chrome's console .json can't retrieve.

angular.module('monservice', ['ngresource']). factory('projet', function($resource){ return $resource('json/accueil'); }); 

i've tried such saving response manually in .json file caching file , use source $resource seems long , complicated...

or using localstorage, :

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 working, anyway what's way using application cache ?

there module built on top of resource caching, on both reading , writing data. should check out. keep copy of data on clients browser , when failed save (due being offline) save locally , keep retrying save.

https://github.com/goodeggs/angular-cached-resource

there small article module:

http://bites.goodeggs.com/open_source/angular-cached-resource/


Comments