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