Let's discuss:
Do we need SW on watch by default?
Do we need SW on build by default?
Things worth mentioning:
1- We have over 20 issues both open and closed on here (at least) with Service Worker problem and or how to disable it.
2- We don't have any tests for SW builds which can lead to a slight risk especially if the cli user was not aware or know enough about SW.
3- I'm a big SW & PWA fan and I run SydPWA Meetup & use it in all my websites.
My openion:
I want SW on watch, but only when I need to, I build a apps that fetch data from Cache first and need SW to cache responses, but that's only 5% of my Preact CLI apps and experiments and I'd like to be in no SW mode first until I decide my app needs it and I opt in with a flag in npm watch script.
in prod, I want to opt in also to get it, forcing SW on people is not a way to make the web faster and teach them about PWAs.
More soon when I'm not on mobile.. I want to hear everyone's opinion first.
An easy middle ground, for me, is preact watch --sw which build and attaches a service worker _for those who want it and/or are aware of it._
It should always be on & attached for production builds imo. This is a main pillar of PWA so must be there. The --no-sw will remain for those who don't want it for a particular reason.
Thanks for opening the debate! Let's see what the others / anyone has to say! 馃帀
_Looking for community feedback._
If we going to allow --no-sw in prod we should have something instead to unregister old one & clear the cache.. this is another real users issue.
Tests with puppeteer is recommended too.
Yes, this is mentioned in #420
Here are my 2 cents on this.
In dev mode (preact watch), I wouldn't cache the assets since wherever some changes made in the JS files, they will not reflect in the UI until you hard refresh because the strategy is cache first in CLI.
As @lukeed suggested, we can provide a flag --sw flag to preact watch command if the user wants the SW to be loaded in the development mode.
We can do the following while running preact watch: check for Service worker and then unregister it before starting a server.
This is a bit of an hack, but might work just fine in dev mode.
We always have to ship a SW file.
If preact watch --sw: file content are our SW stuff.
If preact watch: sw file content is SW unregisterar stuff.
Same for prod in my opinion.
Given that is always in prod. I wonder if disabling SW in dev might lead to devs freaking out about why their prod apps look stale?
I am supportive of no-sw behind a flag in watch mode. Cuz while it makes it comparable to the way of building your web app pre-PWA era, you start missing out on testing runtime strategies for your APIs.
Building offline UX for my web apps is something that my dev environment should support first class.
Its your choice if u don't want SW and hence we should provide a flag, but an opt-in flag might just paint the picture of offline UX as an after thought.
Already a bunch of best in the class players just support loading shell in offline mode and fail miserably in showing actual data.
Also
If we going to allow --no-sw in prod we should have something instead to unregister old one & clear the cache.. this is another real users issue.
This shouldn't be the concern of this flag at all. Managing your service workers should be a separate thing, may be a plugin but not this flag.
Closing this as Luke submitted a fix for this.
Most helpful comment
An easy middle ground, for me, is
preact watch --swwhich build and attaches a service worker _for those who want it and/or are aware of it._It should always be on & attached for production builds imo. This is a main pillar of PWA so must be there. The
--no-swwill remain for those who don't want it for a particular reason.Thanks for opening the debate! Let's see what the others / anyone has to say! 馃帀
_Looking for community feedback._