0

I'm writing a web app, where the user can download images for a later offline usage using the Cache API.

// when the user clicks the download button
window.caches.open("imageCache").then(function(cache) {
          cache.add(imageUrls)
              .then(() => console.log("image cached"))
              .catch((e) => console.error(e));
      });

This works as expected. Using the Chrome-Developer-Tools (under Application -> Cache Storage) I see the list of images:

Now, when I want to display the images in offline-mode using simple img-Tags, it does not work for images that are served from a Google Cloud Bucket, but it does work with other image-sources.

Image from Google Cloud Buckets fails to load in offline mode:

Image from fakeimg.pl shows up in offline mode:

Any idea why it's not working?

hendra
  • 2,531
  • 5
  • 22
  • 34

1 Answers1

0

The culprit in this case was vary: Origin. But I noticed that Chrome seems to be the only browser that makes use of images that are cached with the Cache API without using a service worker anyway.

So I implemented a service-worker with workbox now and it works.

hendra
  • 2,531
  • 5
  • 22
  • 34