File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
packages/react-scripts/template/src Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change 1010
1111export default function register ( ) {
1212 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+
1322 window . addEventListener ( 'load' , ( ) => {
1423 const swUrl = `${ process . env . PUBLIC_URL } /service-worker.js` ;
1524 navigator . serviceWorker
You can’t perform that action at this time.
0 commit comments