Я в файле service-worker.js пытаюсь кэшировать данные JSON из конечной точки API для Progressive Web App.
Это создает файл погоды в кеше, но его содержимое - моя HTML-страница.Если я console.log (data), я вижу нужный мне объект.
Я пробовал cache.add (JSON.stringify (data)) и cache.addAll (data) безрезультатно.
self.addEventListener('install', event => {
event.waitUntil(
caches.open('weather')
.then(function(cache) {
fetch('/api/weathercurrent')
.then(function(response) {
return response.json();
})
.then(function(data) {
cache.add(data);
})
})
)
});