You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you know that you won't be using service workers, or if you'd prefer to use a
35
+
different approach to creating your service worker, don't create a
36
+
`src/service-worker.js` file. The `InjectManifest` plugin won't be run in that
37
+
case.
11
38
12
-
In order to opt-in to the offline-first behavior, developers should look for the
13
-
following in their [`src/index.js`](https://github.com/facebook/create-react-app/blob/master/packages/cra-template/template/src/index.js) file:
39
+
In addition to creating your local `src/service-worker.js` file, it needs to be
40
+
registered before it will be used. In order to opt-in to the offline-first
41
+
behavior, developers should look for the following in their
for your HTML, ensuring that your web app is consistently fast, even on a slow
81
+
or unreliable network.
28
82
29
-
- All static site assets are cached so that your page loads fast on subsequent visits, regardless of network connectivity (such as 2G or 3G). Updates are downloaded in the background.
30
-
- Your app will work regardless of network state, even if offline. This means your users will be able to use your app at 10,000 feet and on the subway.
31
-
- On mobile devices, your app can be added directly to the user's home screen, app icon and all. This eliminates the need for the app store.
83
+
Note: Resources that are not generated by `webpack`, such as static files that are
to apply the runtime caching strategy of your choice to those resources.
89
+
90
+
## Customization
91
+
92
+
Starting with Create React App 4, you have full control over customizing the
93
+
logic in this service worker, by creating your own `src/service-worker.js` file,
94
+
or customizing the one added by the `cra-template-pwa` (or
95
+
`cra-template-pwa-typescript`) template. You can use [additional
96
+
modules](https://developers.google.com/web/tools/workbox/modules) from the
97
+
Workbox project, add in a push notification library, or remove some of the
98
+
default caching logic. The one requirement is that you keep `self.__WB_MANIFEST`
99
+
somewhere in your file, as the Workbox compilation plugin checks for this value
100
+
when generating a manifest of URLs to precache. If you would prefer not to use
101
+
precaching, you can just assign `self.__WB_MANIFEST` to a variable that will be
102
+
ignored, like:
32
103
33
-
However, they [can make debugging deployments more challenging](https://github.com/facebook/create-react-app/issues/2398) so, starting with Create React App 2, service workers are opt-in.
104
+
```js
105
+
// eslint-disable-next-line no-restricted-globals
106
+
constignored=self.__WB_MANIFEST;
34
107
35
-
The [`workbox-webpack-plugin`](https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin)
36
-
is integrated into production configuration,
37
-
and it will take care of generating a service worker file that will automatically
38
-
precache all of your local assets and keep them up to date as you deploy updates.
39
-
The service worker will use a [cache-first strategy](https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#cache-falling-back-to-network)
40
-
for handling all requests for local assets, including
0 commit comments