I am using workbox-webpack-plugin, below is code in webpack config
new GenerateSW({
runtimeCaching: [
{
urlPattern: new RegExp('^https://devapi\.mysite\.xyz/'),
handler: 'staleWhileRevalidate',
options: {
cacheableResponse: {
statuses: [200]
}
}
}
]
})
Below is flow of stale while revalidate strategy as per google doc
I am calling API from cross domain, what I observed is each time response is given back to UI not from cache but from network call response.
I am expecting when same API is called 2nd time, I should get response from cache and then cache should be updated from response of network call.
I think all the info in this "Handle Third Party Requests" guide should help.
In particular, make sure that your remote server is using CORS, or else you'll get back a
response
that has a status of0
. You're explicitly configuring thecacheableResponse
plugin to only cache responses with a status of200
.