简体   繁体   中英

Service Worker - Image Caching

I use my Service Worker to cache some images using Ajax GET function to the URL of the image I want to cache in order to be able to display this image in the future without being online.

At some point in my project, I need to create an Image constructor instance and pass the URL of a cached image as a source. When I do this, the response of caches.match(event.request).then((response) is always null.

If anyone has any idea why will be very helpful!

(Moving this from the comments.)

This sounds like it's due to the presence of a Vary: header on your requests. By default, the vary logic will apply to the Cache Storage API's match() , which can lead to "mysterious" cache read failures.

Setting the ignoreVary: true option when calling match() is a way of opting-out of this logic, and just matching based on URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM