Skip to content

feat(pwa) use offline-plugin for service worker setup and offline sup… #3000

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 8 commits into from
May 8, 2019

Conversation

EugeneHlushko
Copy link
Member

@EugeneHlushko EugeneHlushko commented May 7, 2019

Note:

  • moved ssg config out as webpack was compiling both in a race (at least on my machine it seemed so.) to now run ssg and then run prod and include ssg run's css that was printed into html files.

@EugeneHlushko EugeneHlushko requested a review from montogeek May 7, 2019 09:20
@netlify
Copy link

netlify bot commented May 7, 2019

Preview is ready

Built with commit 98b2b30

https://deploy-preview-3000--webpackjsorg-netlify.netlify.com

@montogeek
Copy link
Member

How does this work?

@EugeneHlushko
Copy link
Member Author

EugeneHlushko commented May 7, 2019

It registers a service worker who then caches network requests making them load from memory first and let it all work offline. There are defaults enlisted in offline-plugin's readme on options section.

@EugeneHlushko
Copy link
Member Author

@EugeneHlushko
Copy link
Member Author

So looks like SSG prod version doesnt need it at all, instead of doing it twice we are doing it once now

@EugeneHlushko
Copy link
Member Author

On the preview its still not perfect, for some reason not all css are there when offline

@montogeek
Copy link
Member

On the preview its still not perfect, for some reason not all css are there when offline

Good luck in your adventures :D

Services Workers are hard.

@@ -1,111 +1,34 @@
// Import External Dependencies
const merge = require('webpack-merge');
const SSGPlugin = require('static-site-generator-webpack-plugin');
Copy link
Member Author

Choose a reason for hiding this comment

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

moved out due to race between webpack runs [ssg, prod]

@EugeneHlushko
Copy link
Member Author

@montogeek ready for review, seem to work as expected

@@ -35,7 +35,7 @@
"fetch:supporters": "node src/utilities/fetch-supporters.js",
"fetch:starter-kits": "node src/utilities/fetch-starter-kits.js",
"prebuild": "npm run clean",
"build": "run-s fetch content && cross-env NODE_ENV=production webpack --config webpack.prod.js",
"build": "run-s fetch content && cross-env NODE_ENV=production webpack --config webpack.ssg.js && cross-env NODE_ENV=production webpack --config webpack.prod.js",
Copy link
Member

Choose a reason for hiding this comment

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

This run-s doesn't work if you append the ENV variable at the beginning?

@@ -77,6 +82,7 @@ class Site extends React.Component {
<Route path="/vote" component={Vote} />
<Route path="/organization" component={Organization} />
<Route path="/starter-kits" component={StarterKits} />
<Route path="/app-shell" component={() => <React.Fragment />} />
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is "empty" state of the page for service worker to serve when offline, our bundle can then render content onto it on clientside. We have two different page templates: home and content pages. Homepage is always saved in SW and this one is used as fall back for the rest to not download all of them to disk when installing service worker, as client doesnt really need SSR version of the page.

@montogeek montogeek merged commit 3854b23 into master May 8, 2019
@montogeek
Copy link
Member

Thanks!

@montogeek montogeek deleted the pwa/offline-plugin branch May 8, 2019 16:10
@hulkish hulkish mentioned this pull request May 8, 2019
13 tasks
@chenxsan chenxsan mentioned this pull request Nov 3, 2020
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants