Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for precached assets hosted on a CDN #604

Closed
jeffposnick opened this issue Jun 7, 2017 · 3 comments
Closed

Support for precached assets hosted on a CDN #604

jeffposnick opened this issue Jun 7, 2017 · 3 comments

Comments

@jeffposnick
Copy link
Contributor

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'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.

@gauntface
Copy link

We need to stop bolting on options.

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.

@jeffposnick
Copy link
Contributor Author

Sure—take a look at the proposal in #626, and if you're on board with that, then it would supersede this feature request.

@gauntface
Copy link

Can we close this in favor of #626?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants