We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3e9955d commit a7d31d9Copy full SHA for a7d31d9
packages/react-scripts/template/src/registerServiceWorker.js
@@ -10,6 +10,15 @@
10
11
export default function register() {
12
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
13
+ // The URL constructor is available in all browsers that support SW.
14
+ const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
15
+ if (publicUrl.origin !== window.location.origin) {
16
+ // Our service worker won't work if PUBLIC_URL is on a different origin
17
+ // from what our page is served on. This might happen if a CDN is used to
18
+ // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
19
+ return;
20
+ }
21
+
22
window.addEventListener('load', () => {
23
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
24
navigator.serviceWorker
0 commit comments