You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A use case that comes up every now and then is deployments in which HTML pages (and the SW script) are hosted on a first-party server, but all assets are hosted on a third-party CDN.
We currently sort-of support this by using workbox-build's modifyUrlPrefix option to add in the CDN's origin to the start of asset URLs when writing out the precache manifest, but it's difficult to do that without also adding in the CDN origin to the start of any HTML URLs.
A possible alternative would be to take in a publicPath option. If passed in, it would be prepending to any URLs in the precache manifest that we identify as being asset URLs. Identifying non-asset URLs would require a bit of guesswork, so the heuristic might be:
Does the URL end in .html?
Is the URL a key in templatedUrls?
Is the URL passed in as the navigateFallback option?
We can automate things for the Webpack wrapper on top of workbox-build by checking to see if Webpack's publicPath is set, and if so, use that value as the implied publicPath for workbox-build.
One complication is that this should only work if the CDN supports CORS, because precaching opaque responses and serving them cache-first isn't a good practice.
The text was updated successfully, but these errors were encountered:
A better solution for this, and probably untold other random scenarios is to supply a callback that gives developers a way to get the url and revision and manipulate before it's finally stamped out to the service worker.
Library Affected:
workbox-build
,workbox-webpack-plugin
A use case that comes up every now and then is deployments in which HTML pages (and the SW script) are hosted on a first-party server, but all assets are hosted on a third-party CDN.
We currently sort-of support this by using
workbox-build
'smodifyUrlPrefix
option to add in the CDN's origin to the start of asset URLs when writing out the precache manifest, but it's difficult to do that without also adding in the CDN origin to the start of any HTML URLs.A possible alternative would be to take in a
publicPath
option. If passed in, it would be prepending to any URLs in the precache manifest that we identify as being asset URLs. Identifying non-asset URLs would require a bit of guesswork, so the heuristic might be:.html
?templatedUrls
?navigateFallback
option?We can automate things for the Webpack wrapper on top of
workbox-build
by checking to see if Webpack'spublicPath
is set, and if so, use that value as the impliedpublicPath
forworkbox-build
.One complication is that this should only work if the CDN supports CORS, because precaching opaque responses and serving them cache-first isn't a good practice.
The text was updated successfully, but these errors were encountered: