9

I am a bit confused with regards to availability of Caches API on mobile devices.

https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage

Documentation states this API is available on both service worker scope and window scope.

I can clearly access it on desktop's Chrome without issues.

Now whenever I do feature detection on Android's Chrome I get undefined as if feature is not available.

I tried to detect this way:

if ('caches' in window)...
if ('caches' in self)...

calling from console log via connected device etc

What do I miss?

PS: I understand Safari has very basic implementation so I expected this to go wrong with Safari, but here I am testing it with Chrome on Android;/

Sergey Rudenko
  • 8,809
  • 2
  • 24
  • 51

1 Answers1

9

It seems window.caches (CacheStorage) is only available on chrome mobile when the page is served through SSL.

I'm testing with my Progressive Web App (PWA), containing a Service-Worker for caching and a manifest file.

When serving the PWA via HTTP over the LAN window.caches is not available. When served via a domain-name with SSL enabled, window.caches is available and behaves like on the Desktop-Version of chrome. It doesn't make a difference, whether you run it in a browser tab or standalone (when added to home-screen).

Edit: In fact, the same behavior also applies to chrome on desktop. Caching on my app was working only, because i tested with 'localhost' or 127.0.0.1. On any other domain / ip-address, caching gets denied when not using ssl.

uhon
  • 195
  • 1
  • 9
  • Chromium bug report: https://bugs.chromium.org/p/chromium/issues/detail?id=1026063 – Ian Dunn Nov 19 '19 at 00:50
  • 5
    If you're developing a WebApp which is served over a custom hostname (other than localhost or 127.0.0.1), you can add an exception for this host in Chrome-Flags to treat it as secure origin. `chrome://flags/#unsafely-treat-insecure-origin-as-secure` This enables cache-api (and many other browser functionality) for the hostname. – uhon Apr 05 '20 at 10:22