-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Failed to register a ServiceWorker when PUBLIC_URL is CDN #2374
Comments
cc @jeffposnick We allow people to compile with |
Ah, I wasn't aware of So... I guess changing this line to: if (!process.env.PUBLIC_URL && process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// registration
} would work? Does |
Yep, it should be. |
AFAIK we always provide We'd probably need to do |
That makes sense, @Timer. You know those environment variables better than I do, so anything you think along those lines that would detect a different origin would make sense. (I normally do this sort of thing by constructing |
Fixed in 1.0.8. Please verify. |
(you'll need to follow migration instructions since this change won't be migrated to your project automatically) |
All things work well, thank you all. |
Why not also use service worker when We can serve |
i agree with @vincentbel i want to serve js/css/images from CDN and still want to precache them.. currently i has problem with service worker after setup PUBLIC_URL to my cdn server lets say that i has
the precached files are
and there are lines like this in generated service worker.js
the results are
|
@hartono-sulaiman-kaskus, what you describe is expected after #2432 went into effect. The history behind that PR can be found upthread. There are definitely scenarios in which you can configure everything properly to safely use a service worker while retrieving all of your assets from a CDN, but doing so requires a lot of assumptions (such as: your CDN supports CORS, that the deployment of your (If you want to manually update your service worker configuration, post- |
Can you reproduce the problem with latest npm?
Yes.
Description
When set
PUBLIC_URL
to a cdn address, service worker registration is blocked. It seems a cross-domain problem:Expected behavior
ServiceWorker should work well when
PUBLIC_URL
isn't local host.Actual behavior
ServiceWorker doesn't work.
Environment
npm ls react-scripts
(if you haven’t ejected): [email protected]node -v
: v7.10.0npm -v
: v4.2.0Then, specify:
Reproducible Demo
See console output on my website.
The text was updated successfully, but these errors were encountered: