AngularJS - browser caching JSON data -


i creating application using angularjs framework.

the problem:

when jump out of application different domain or page , when use history button app, json. same situation happens when jump out of app browsing in history, , when use forward button go app, again json back. back/forward works fine within app, happens when go different domain.

why that? think related caching how, because when back/forward app, no request send server.

you can see i'm talking if go url - http://test.deving.cz/admin/prihlasit/. go , forward.

my setup:

my app configured use html5 history api. url starts mydomain.com/admin/ return index.hmtl containing angular. every other url in app 2 requests send out. 1 template , 1 data (the json).

example:

$routeprovider.when('/admin/page/', {controller: 'pagelistctrl', templateurl: '/templates/page/list/', resolve: 'pagelistctrl.resolve'})

pagelistctrl:

angular.module('page').controller('pagelistctrl', ['$scope', 'data', function($scope, data) {     $scope.pages = data; }]); 

resolve function:

resolve = {data:              function($http, $q){                 var delay = $q.defer();                 $http.get().success(function(data){                     delay.resolve(data['data']);                 });                 return delay.promise;             }         } 

how should configure angular or app tell browser not cache data , index.html , let angular requests?

i got same problem. while found workaround problem, think there must exist better solution. if have more better solution please let me know.

the server side framework i'm using rails. add following code

  response.headers["cache-control"] = "no-cache, no-store, max-age=0, must-revalidate"   response.headers["pragma"] = "no-cache"   response.headers["expires"] = "fri, 01 jan 1990 00:00:00 gmt" 

these lines prevent browser cache request, , can detect whether request xhr decide add above lines or not.


Comments