Is it possible to deep-fetch external images?
Here’s an example of service-worker.js
file code:
-
console.info
is getting called -
prefetch(url)
call doesn’t make it -
https://external-images-domain.net
hasaccess-control-allow-origin: *
response header
import { skipWaiting, clientsClaim } from 'workbox-core'
import { precacheAndRoute } from 'workbox-precaching'
import { Prefetcher, prefetch } from "@xdn/prefetch/sw"
import DeepFetchPlugin from "@xdn/prefetch/sw/DeepFetchPlugin"
skipWaiting()
clientsClaim()
precacheAndRoute(self.__WB_MANIFEST || [])
new Prefetcher({
plugins: [
new DeepFetchPlugin([
{
jsonQuery: 'pageProps[*].product_image:filter',
jsonQueryOptions: {
locals: {
filter: images => images.map((img, i) => {
console.info(`DeepFetchPlugin (filter) | img [${i}]: `, img);
prefetch(img);
return img;
}),
},
},
maxMatches: 10,
as: 'image',
cors: false,
},
]),
],
})
.route()
.cache(/^https:\/\/external-images-domain\.net\/.*/);