iOS 12 Safari CacheStorage API gets deleted after browser restart

Dear all,


I'm facing an issue regarding usage of the ServiceWorker and CacheStorage API.

This issue only occurs on the new iOS 12.x releases. With iOS 11.x, it worked fine.


CacheStorage is an API that let's you store a Request object (or URL) and a response.

We use this to cache all application resources for making the application available offline.

However, after a restart of the browser (going to the iOS task manager and manually closing Safari), the CacheStorage is emptied.


I prepared a small demo to test this (see "Steps to reproduce").

The expected outcome is, that after a browser restart, the CacheStorage should still be there and the resources need to be still in it.

Otherwise this would completely break offline usage.


Steps to reproduce

  1. Go to https://itoobi.github.io/servicebreaker/
  2. The page says "keys: size: 0" (0 caches currently)
  3. It creates a new cache called "test" and says "cache opened".
  4. Reload the page
  5. The page now says "keys: test size: 1" (1 cache existing) (and again "cache opened", but thats not important here)
  6. Close the browser (by closing it in the iOS task manager)
  7. Restart browser and reload the page
  8. It should now say again "keys: test size: 1", as there should be an existing cache. --> on iOS 12, the page again says "keys: size: 0" here, so there is no existing cache.


Code of the demo page:


caches.keys().then(function(keys){
            alert("keys: "+keys+" size: "+keys.length);
        });
        caches.open("test").then(function(cache){
            cache.add("mario.png");
            alert("cache opened");
        });


The demo was tested on different devices with different iOS versions:

  • iPad 5th Gen (2017) with iOS 11.4: PASS
  • iPad Pro 12.9 with iOS 12.1 Beta 5: FAILED
  • iPad Air 2 with iOS 12.1: FAILED
  • iPad Air 2 with iOS 11.4: PASS
  • iPhone 7 with iOS 12.0.1: FAILED


Maybe the API implemenation was changed, or a new API is in place, or this could also be a bug in Safari.

Does anybody know a fix/workaround for this or experiences similar issues?



Kind regards,

Tobias G

Replies

Hi Tobias,


I get the exact same issue as you do.

This ticket is related to adding to the home screen the PWA, but it seems to still not be working on iOS 12.1.

https://bugs.webkit.org/show_bug.cgi?id=190269


The problems also appear to me when closing and reopning safari, not even adding the PWA to the home screen.