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

[docs] Add precaching Service Worker to exported docs builds #10267

Merged
merged 2 commits into from Feb 15, 2018
Merged

[docs] Add precaching Service Worker to exported docs builds #10267

merged 2 commits into from Feb 15, 2018

Conversation

msiadak
Copy link
Contributor

@msiadak msiadak commented Feb 13, 2018

Closes #9529

Given that we're deploying a static export of the docs website to Firebase, I think we only need to create a service worker for that case rather than trying to address the builds served with the docs:dev and docs:start scripts.

To accomplish this I used the new beta (v3.0.0-beta.0) of Workbox to crawl the docs/export directory and inject a manifest of the exported files into a simple Service Worker template. I wrapped this action in a new npm script: docs:build-sw that I added into the docs:export script. If we decide that we want to do something more complex with the Service Worker in the future, I think this can provide a decent starting point.

Before taking this approach, I looked into some of the other known methods for automating service workers with next.js, but I wasn't able to get any of them working for the static export case without also using a method like the one in this PR.

I was able to get all of the PWA audits on Lighthouse to pass with this configuration with the exception of the https-related ones, although those should be covered by Firebase hosting.

@mbrookes mbrookes added the docs Improvements or additions to the documentation label Feb 13, 2018
@oliviertassinari oliviertassinari self-assigned this Feb 14, 2018
@@ -242,6 +242,12 @@ function withRoot(Component) {
};
}

componentDidMount() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js');
Copy link
Member

Choose a reason for hiding this comment

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

I'm gonna use sw.js as the convention.

Copy link
Member

Choose a reason for hiding this comment

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

@oliviertassinari
Copy link
Member

@msiadak Hold on. I'm making some changes :)

@msiadak
Copy link
Contributor Author

msiadak commented Feb 14, 2018

My bad, will stand by. Thanks for reviewing!

@oliviertassinari
Copy link
Member

@msiadak Alright, I'm pretty happy with this pull-request. The documentation now works offline. It's huge.

@oliviertassinari oliviertassinari merged commit bf7feca into mui:v1-beta Feb 15, 2018
@oliviertassinari
Copy link
Member

@msiadak Thank you.

@msiadak msiadak deleted the workbox branch February 15, 2018 13:11
caub pushed a commit to caub/material-ui that referenced this pull request Feb 15, 2018
* Add service worker to exported docs builds

* push forward
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants