Skip to content
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

Disable service worker by default #3817

Merged
merged 6 commits into from
Jan 19, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/react-scripts/template/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import registerServiceWorker, {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing both of these results in a lint error because only one of them is ever used. We could override eslint for this line, we could only import one and update the comment below (ugh) or we could do something else entirely like only using registerServiceWorker and passing it a boolean to enable/disable.

unregister as unregisterServiceWorker,
} from './registerServiceWorker';

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();

// By default we make sure that no service worker is registered. If you would
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

People reading this probably don't know what service worker is.
Can you rewrite this so it's a bit less wordy, and also understandable to most folks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that's a challenge! 😀

I guess we can remove the first sentence and maybe link to that Google page from the docs about what a service worker is. Alternatively we could just link to the "Making a Progressive Web App" section of the CRA docs. I'll work on it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking something like

// If you want your app to work offline and load faster, you can change “disable” below to “enable”.
// Note this comes with some deployment pitfalls.
// Learn more about service workers: <...>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it helps, https://developers.google.com/web/fundamentals/primers/service-workers/ attempts to be a one-stop landing page for a service worker overview, and https://developers.google.com/web/progressive-web-apps/ is a similar landing page for PWAs in general.

// like to enable service worker uncomment the call to registerServiceWorker()
// and comment out the call to unregisterServiceWorker().
// See http://bit.ly/2vJdu84 for more information.

// registerServiceWorker();
unregisterServiceWorker();