angular / mobile-toolkit

Tools for building progressive web apps with Angular
MIT License
1.34k stars 175 forks source link

Disable cache for api calls? #145

Closed fseebach closed 7 years ago

fseebach commented 7 years ago

I've setup the serviceworker for an angular-cli project (Angular4) The service worker works great for making the app run out of the cache!

Hower i noticed that in offline mode ALL requests to my backend are served from cache if they were requested once while online. Is there any possibility to turn off caching for urls? In my case everything to /api/** should bypass cache since the app always needs the latest data. I want to display an error in case of no connection.

gkalpak commented 7 years ago

I think you are looking for "static.ignore" (e.g. as seen here).

webmaxru commented 7 years ago

@fracoon are you sure about it's NGSW the one which caches/retrieves from the cache API calls? The Dynamicplugin, which could do it, is not merged to master yet: https://github.com/angular/mobile-toolkit/pull/141

For the moment, only Static (install-time) caching is available (ignore is related to Static only), so the API calls intercepting fact sounds really strange

gkalpak commented 7 years ago

@webmaxru, I am also seeing this. Resources that requested when online are cached and can later be retrieved by the ServiceWorker when offline.

Isn't that expected?

fseebach commented 7 years ago

In my case you are right @webmaxru ... It was not coming from the serviceworker. The data was held in the service and displayed from there.. Clearing out the data on http error solved the "problem"

webmaxru commented 7 years ago

@gkalpak are you about the app files themselves (app shell) or about API calls responses? The last ones should not be processed by NGSWat all. If you have these - check the possible leftovers of other SWs registered against your app

gkalpak commented 7 years ago

@webmaxru, you are right. The data was coming from the app (although the Network tab shows "From ServiceWorker") :confused:

webmaxru commented 7 years ago

@fracoon Could you please close the issue then?