Ayelet
Ayelet

Reputation: 1743

Angular.js - $http.get - use cache from file

Is it possible to use a file (.js / .json) the angular.js cache for $http.get?

We have an angular application, and we want to download some pages and view them offline. So, the idea is, before downloading, we make all the necessary $http.get calls, and save the responses in some json / js file. When we open the pages offline, we want the $http.get calls to access this file and use it as a cache.

It sounds like it should be possible, but I'm new to angular, so I'm not sure how to configure that.

Upvotes: 0

Views: 829

Answers (2)

Jagdeep Singh
Jagdeep Singh

Reputation: 11

Hey this might help you jsCache

You can store api data in storage of your choice for desired time period you want. Just have an look @ https://github.com/funwithjs/jsCache

Upvotes: 0

shershen
shershen

Reputation: 10003

You can utilise following techniques:

  1. Browser's localStorage, angular-local-storage
  2. Service worker to intelligently recache requests, configurable plugin sw-precache for you build tool

Besides that:

  • you can enable caching of $http.get requests:

    $http({ cache: true, url: url, method: 'GET'}).success(...);

  • you can make use of angular $templateCache : https://docs.angularjs.org/api/ng/service/$templateCache

Upvotes: 1

Related Questions