-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Conversation
Preview is ready Built with commit 98b2b30 https://deploy-preview-3000--webpackjsorg-netlify.netlify.com |
How does this work? |
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. |
So looks like SSG prod version doesnt need it at all, instead of doing it twice we are doing it once now |
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'); |
There was a problem hiding this comment.
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]
…p shell, now everything offline
@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", |
There was a problem hiding this comment.
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 />} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
There was a problem hiding this comment.
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.
Thanks! |
Note: