Reputation: 69
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!
Upvotes: 0
Views: 1019
Reputation: 56044
(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.
Upvotes: 2