Cache persistance in PWA in iOS

Viewed 246

Have a PWA that works fine with network connection. Added a service worker and it works with no connection IF the PWA had been opened at some point before loss of network connection. So far, so good.

If I force quite the PWA (swipe up on the iPhone) then try the PWA, it is blank and asks for a network connection. Is that normal? Does force quitting an app clear the cached files? Or am I missing something?

Service Worker code:

    var cacheName = 'floorwork';
    var filesToCache = [
    '/',
    '/index.html',
    '/themes/basicblue.min.css',
    '/themes/jquery.mobile.icons.min.css',
    '/images/carltonsig.png',
    '/images/claw1.jpg',
    '/images/GLSeal.jpg',
    '/js/jquery-1.11.1.js',
    '/js/jquery.mobile-1.4.5.min.js'
    ]; 

    self.addEventListener('install', function(e) {
    e.waitUntil(
    caches.open(cacheName).then(function(cache) {
    return cache.addAll(filesToCache);
    })
    );
    });  

    self.addEventListener('fetch', function(e) {
    e.respondWith(
    caches.match(e.request).then(function(response) {
    return response || fetch(e.request);
    })
    );
    });
   
1 Answers

I am using the following code to persist the data:

navigator.storage.persist().then(function(persistent) {
                if (persistent)
                    console.log("Storage will not be cleared except by explicit user action");
                else
                    console.log("Storage may be cleared by the UA under storage pressure.");
            });

That all seems fine after closing the app and reopening BUT as per my other question just asked (to which I have no answer as yet) I am having problems with the PWA cache after I power the phone off and back on if I bring the phone up in airplane mode before visiting the app. So I guess my answer may solve part of your problem but may not solve everything.

Related