Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use browser cache for AngularJS JSON requests ($http/$resource)?

We're developing an app with AngularJS and RESTful services. The data returned by services is changed infrequently and I very much would like to cache responses for a period of time. I'm setting Cache-Control: no-transform, max-age=604800 in the response.

Is there a way to have AngularJS JSON requests ($http/$resource) respect browser cache instead of using completely parallel built-in AngularJS cache (http://www.metaltoad.com/blog/angularjs-vs-browser-http-cache) or angular-cache library (http://angular-data.pseudobry.com/documentation/api/angular-cache)? From what I can see watching the network, by default $http requests are ignoring Cache-Control headers.

like image 834
Dmitriy Korobskiy Avatar asked Dec 30 '25 08:12

Dmitriy Korobskiy


1 Answers

The browser will respect the cache time set by the response for that particular asset. Any subsequent GET should look to the cache until the timeout is reached.

Its possible you have devtools ignoring this.

like image 154
Dane Macaulay Avatar answered Jan 01 '26 20:01

Dane Macaulay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!