- 
          
- 
        Couldn't load subscription status. 
- Fork 27.1k
Switch to the Workbox InjectManifest plugin #9205
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
          
     Merged
      
      
    
  
     Merged
                    Changes from 9 commits
      Commits
    
    
            Show all changes
          
          
            26 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      54d3740
              
                WIP
              
              
                jeffposnick e9fa48b
              
                WIP
              
              
                jeffposnick 5a3a6c7
              
                Rename
              
              
                jeffposnick 0eed437
              
                Use publicPath
              
              
                jeffposnick 3308fb6
              
                Getting closer.
              
              
                jeffposnick b0cab1b
              
                Move off of NavigationRoute
              
              
                jeffposnick 53b142a
              
                Update the PWA guide
              
              
                jeffposnick 8707cc7
              
                Don't precache any LICENSEs.
              
              
                jeffposnick d2545aa
              
                Updated the ignore instructions
              
              
                jeffposnick 3ee8b1f
              
                skipWaiting message handler
              
              
                jeffposnick a893129
              
                Added a comment
              
              
                jeffposnick 8ff1fe3
              
                Merge branch 'master' into wb-inject-manifest
              
              
                ianschmitz f96d1d2
              
                Add back web vitals to typescript template
              
              
                ianschmitz c674f01
              
                Add web vitals back to javascript template
              
              
                ianschmitz d22c7dc
              
                Change references of CRA 3 to 4
              
              
                ianschmitz 563589c
              
                Add webworker lib ref
              
              
                ianschmitz 49b27d5
              
                Fix TypeScript errors in service-worker.ts
              
              
                ianschmitz f8245c9
              
                Add back eslint disable comment
              
              
                ianschmitz f3adc73
              
                Ignore restricted-globals across entire file
              
              
                ianschmitz 94d6494
              
                Runtime caching
              
              
                jeffposnick d949faa
              
                Explicitly depend on Workbox libs
              
              
                jeffposnick b02ebb4
              
                Remove SW and package.json deps
              
              
                jeffposnick 7f768c9
              
                WIP update to README.
              
              
                jeffposnick 34a46dc
              
                Updates to the docs.
              
              
                jeffposnick 419a883
              
                Explicitly require InjectManifest
              
              
                jeffposnick 991e683
              
                Switch back.
              
              
                jeffposnick File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            50 changes: 50 additions & 0 deletions
          
          50 
        
  packages/cra-template-typescript/template/src/service-worker.ts
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // This service worker can be customized! | ||
| // See https://developers.google.com/web/tools/workbox/modules | ||
| // for the list of available Workbox modules, or add any other | ||
| // code you'd like. | ||
| // You can also remove this file if you'd prefer not to use a | ||
| // service worker, and the Workbox build step will be skipped. | ||
|  | ||
| declare const self: ServiceWorkerGlobalScope; | ||
|         
                  jeffposnick marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
|  | ||
| import {clientsClaim} from 'workbox-core'; | ||
| import {precacheAndRoute, createHandlerBoundToURL} from 'workbox-precaching'; | ||
| import {registerRoute} from 'workbox-routing'; | ||
|  | ||
| clientsClaim(); | ||
|  | ||
| // Precache all of the assets generated by your build process. | ||
| // Their URLs are injected into the manifest variable below. | ||
| // eslint-disable-next-line no-restricted-globals | ||
| precacheAndRoute(self.__WB_MANIFEST); | ||
|  | ||
| // Set up App Shell-style routing, so that all navigation requests | ||
| // are fulfilled with your index.html shell. Learn more at | ||
| // https://developers.google.com/web/fundamentals/architecture/app-shell | ||
| const fileExtensionRegexp = new RegExp('/[^/?]+\\.[^/]+$'); | ||
| registerRoute( | ||
| // Return false to exempt requests from being fulfilled by index.html. | ||
| ({request, url}: {request: Request, url: URL}) => { | ||
|         
                  ianschmitz marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| // If this isn't a navigation, skip. | ||
| if (request.mode !== 'navigate') { | ||
| return false; | ||
| } | ||
|  | ||
| // If this is a URL that starts with /_, skip. | ||
| if (url.pathname.startsWith('/_')) { | ||
| return false; | ||
| } | ||
|  | ||
| // If this looks like a URL for a resource, because it contains | ||
| // a file extension, skip. | ||
| if (url.pathname.match(fileExtensionRegexp)) { | ||
| return false; | ||
| } | ||
|  | ||
| // Return true to signal that we want to use the handler. | ||
| return true; | ||
| }, | ||
| createHandlerBoundToURL(process.env.PUBLIC_URL + '/index.html'), | ||
| ); | ||
|  | ||
| // Any other custom service worker logic can go here. | ||
            File renamed without changes.
          
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // This service worker can be customized! | ||
| // See https://developers.google.com/web/tools/workbox/modules | ||
| // for the list of available Workbox modules, or add any other | ||
| // code you'd like. | ||
| // You can also remove this file if you'd prefer not to use a | ||
| // service worker, and the Workbox build step will be skipped. | ||
|  | ||
| import { clientsClaim } from 'workbox-core'; | ||
| import { precacheAndRoute, createHandlerBoundToURL } from 'workbox-precaching'; | ||
| import { registerRoute } from 'workbox-routing'; | ||
|  | ||
| clientsClaim(); | ||
|  | ||
| // Precache all of the assets generated by your build process. | ||
| // Their URLs are injected into the manifest variable below. | ||
| // eslint-disable-next-line no-restricted-globals | ||
|         
                  jeffposnick marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| precacheAndRoute(self.__WB_MANIFEST); | ||
|  | ||
| // Set up App Shell-style routing, so that all navigation requests | ||
| // are fulfilled with your index.html shell. Learn more at | ||
| // https://developers.google.com/web/fundamentals/architecture/app-shell | ||
| const fileExtensionRegexp = new RegExp('/[^/?]+\\.[^/]+$'); | ||
| registerRoute( | ||
| // Return false to exempt requests from being fulfilled by index.html. | ||
| ({ request, url }) => { | ||
| // If this isn't a navigation, skip. | ||
| if (request.mode !== 'navigate') { | ||
| return false; | ||
| } | ||
|  | ||
| // If this is a URL that starts with /_, skip. | ||
| if (url.pathname.startsWith('/_')) { | ||
| return false; | ||
| } | ||
|  | ||
| // If this looks like a URL for a resource, because it contains | ||
| // a file extension, skip. | ||
| if (url.pathname.match(fileExtensionRegexp)) { | ||
| return false; | ||
| } | ||
|  | ||
| // Return true to signal that we want to use the handler. | ||
| return true; | ||
| }, | ||
| createHandlerBoundToURL(process.env.PUBLIC_URL + '/index.html') | ||
| ); | ||
|  | ||
| // Any other custom service worker logic can go here. | ||
            File renamed without changes.
          
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.