Good morning. I am developing a SPA system whose one part is available only when the user is online and another is available even offline. The offline part is configured in the service worker but a problem has started. Routes of the application that uses micro service to dispose the data that is used to assemble the page end up being cached. Which creates an unexpected situation.
The application has the installed service worker as follows:
var version = '0.8';
self.addEventListener('install', function (event) {
event.waitUntil(
caches.open('v1').then(function (cache) {
return cache.addAll([
'/',
'/css/app.css',
'/js/app.js',
'/cache.js',
'/favicon.ico',
'/js/gauge.min.js',
'/manifest.json',
'/avatar.png',
]);
})
);
});
self.addEventListener('fetch', function (event) {
event.respondWith(
caches.open('mysite-dynamic').then(function (cache) {
return cache.match(event.request).then(function (response) {
if (response) {
return response;
} else {
return fetch(event.request).then(function (response) {
cache.put(event.request, response.clone());
return response;
});
}
});
})
);
});
With this code both offline part is available to the user. The problem that all of the micro-services are also routed through the cache. All micro service routes are link * This problem can not find information either in the documentation or in the tutorial sites.
And with that. The big X of the question is that routes of the api do not allow more than one register in the system for example. Soon. Whenever I access the page, post routes are cached. and I can only register an entity in the system, because the browser caches and does not allow me to send post routes to the server.
Would there be a way for the service worker to be configured to operate by providing data only when the system is inaccessible? That is, when resources can not be accessed?