It'd would be _really_ cool if Gatsby could support this architecture by default. Service workers are supported by ~50% of browsers now and this would make the initial paint instant for Gatsby sites on subsequent loads.
Not 100% sure how this would work though. It'd be a great research project if someone wants to investigate.
Some more readings:
As mentioned in #10, it's probably worth looking into offline-plugin.
Isn't the time-to-first-paint even better, however, if the main above the fold content of the page is in plain HTML?
That "static site" part of gatsby seems to be even simpler and faster than reading data from cache via service workers, and then injecting that into the page via JS execution. Plus plain static site content can also be saved offline naturally
@knpwrs woah, offline-plugin looks perfect. I keep underestimating Webpack :) I hadn't thought to go looking for a plugin like this but now that I see it, it makes perfect sense.
@phlogisticfugu quite possibly! This is something we need to research a lot more I think to understand options/tradeoffs. :100: to everyone who wants to play around with this and build a sample site and report back.
Have a look at
https://github.com/mxstbr/react-boilerplate/tree/v3.0.0
Been reading + thinking more about services workers. Current thought is best plan is a) finish #27 and then b) just add a simple pass-through cache for html and cache forever static assets. This is safe since all js, css, other static assets will have unique names.
To get true offline support working, will probably need a fallback html file which will load and render the site using the latest JS bundle.
Glad to see the application shell architecture being considered here. If y'all run into any challenges implementing and have questions feel free to reach out.
@addyosmani thanks Addy! We really appreciate the offer. I've learned a ton from y'all's work there at Google and looking forward to incorporating ideas from App Shell/AMP/PWAs into Gatsby.
So interesting idea I just had heard. One way to use Service Workers + code splitting is that every page has a separate bundle. But then when creating the service-worker file, we first analyze the link structure of the site so that whatever page you land on, you initially load just that pages JS bundle but then the service worker async loads and caches the bundle for every page that page links to. So clicking around the site should be very fast with resources prefetched but the initial fetching remains as small/fast as possible. This could be configurable so say if the user is on a mobile network, you don't prefetch.
Relevant https://twitter.com/slightlylate/status/731203821335023616
This would be sick (though probably create really big build times) https://github.com/gmetais/sw-delta
Offline + caching is coming to 1.0! Plan is to turn them on by default. Wrote up plans at https://github.com/gatsbyjs/gatsby/issues/431
Closing this issue in favor of that one.
Most helpful comment
Glad to see the application shell architecture being considered here. If y'all run into any challenges implementing and have questions feel free to reach out.