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
Updates to reflect service worker registration being opt-in (#3924)
* Updates to reflect service worker registration being opt-in.
* Fixed an anchor link.
* Updates to SWPrecacheWebpackPlugin config, and corresponding docs.
-[Progressive Web App Metadata](#progressive-web-app-metadata)
82
82
-[Analyzing the Bundle Size](#analyzing-the-bundle-size)
@@ -1856,10 +1856,28 @@ Create React App doesn't provide any built-in functionality to publish a compone
1856
1856
1857
1857
## Making a Progressive Web App
1858
1858
1859
-
By default, the production build is a fully functional, offline-first
1860
-
[Progressive Web App](https://developers.google.com/web/progressive-web-apps/).
1859
+
The production build has all the tools necessary to generate a first-class
1860
+
[Progressive Web App](https://developers.google.com/web/progressive-web-apps/),
1861
+
but **the offline/cache-first behavior is opt-in only**. By default,
1862
+
the build process will generate a service worker file, but it will not be
1863
+
registered, so it will not take control of your production web app.
1861
1864
1862
-
Progressive Web Apps are faster and more reliable than traditional web pages, and provide an engaging mobile experience:
1865
+
In order to opt-in to the offline-first behavior, developers should look for the
1866
+
following in their [`src/index.js`](src/index.js) file:
1867
+
1868
+
```js
1869
+
// If you want your app to work offline and load faster, you can change
1870
+
// unregister() to register() below. Note this comes with some pitfalls.
1871
+
// Learn more about service workers: http://bit.ly/CRA-PWA
1872
+
serviceWorker.unregister();
1873
+
```
1874
+
1875
+
As the comment states, switching `serviceWorker.unregister()` to
1876
+
`serviceWorker.register()` will opt you in to using the service worker.
1877
+
1878
+
### Why Opt-in?
1879
+
1880
+
Offline-first Progressive Web Apps are faster and more reliable than traditional web pages, and provide an engaging mobile experience:
1863
1881
1864
1882
* 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.
1865
1883
* 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.
@@ -1872,33 +1890,14 @@ precache all of your local assets and keep them up to date as you deploy updates
1872
1890
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)
1873
1891
for handling all requests for local assets, including
@@ -2080,27 +2084,20 @@ If you’re using [Apache Tomcat](http://tomcat.apache.org/), you need to follow
2080
2084
2081
2085
Now requests to `/todos/42` will be handled correctly both in development and in production.
2082
2086
2083
-
When users install your app to the homescreen of their device the default configuration will make a shortcut to `/`. This may not work if you don't use a client-side router and expect the app to be served from `/index.html`. In this case, the web app manifest at [`public/manifest.json`](public/manifest.json) and change `start_url` to `./index.html`.
created by the production build. Navigations for those URLs will always
2091
-
require a network connection, as opposed to navigations for `/` and
2092
-
`/index.html`, both of which will be served from the cache by the service worker
2093
-
and work without requiring a network connection.
2094
-
2095
-
If you are using the `pushState` history API and would like to enable service
2096
-
worker support for navigations to URLs like `/todos/42`, you need to
2097
-
[`npm eject`](#npm-run-eject) and enable the [`navigateFallback`](https://github.com/GoogleChrome/sw-precache#navigatefallback-string)
2087
+
On a production build, and when you've [opted-in](#why-opt-in),
2088
+
a [service worker](https://developers.google.com/web/fundamentals/primers/service-workers/) will automatically handle all navigation requests, like for
2089
+
`/todos/42`, by serving the cached copy of your `index.html`. This
2090
+
service worker navigation routing can be configured or disabled by
2091
+
[`eject`ing](#npm-run-eject) and then modifying the
and [`navigateFallbackWhitelist`](https://github.com/GoogleChrome/sw-precache#navigatefallbackwhitelist-arrayregexp)
2099
2094
options of the `SWPreachePlugin` [configuration](../config/webpack.config.prod.js).
2100
2095
2101
-
>Note: This is a [change in default behavior](https://github.com/facebook/create-react-app/issues/3248),
2102
-
as earlier versions of `create-react-app` shipping with `navigateFallback`
2103
-
enabled by default.
2096
+
When users install your app to the homescreen of their device the default configuration will make a shortcut to `/index.html`. This may not work for client-side routers which expect the app to be served from `/`. Edit the web app manifest at [`public/manifest.json`](public/manifest.json) and change `start_url` to match the required URL scheme, for example:
0 commit comments