WordPress/wordpress-playground

Offline mode (PWA)

danielbachhuber opened this issue ยท 13 comments

Please use the project scoping PR to discuss this feature

Network access on contributor days is always problematic.

Once we have something like #104, it would be helpful to have offline support for WordPress Playground. This way, a new contributor could download WordPress Playground once and then be able to use it for the rest of the day.

If WordPress Playground was a Progressive Web App, it could be:

  • Used on a phone
  • Used for offline apps in general (like notes, cc @ellatrix)
  • Handy as a development environment
  • Downloaded once and used for the rest of the day (handy for Contributor Days on WordCamps where network access is always a problem)

Technically, this would require downloading all the WordPress assets that are currently now hosted on the server. Doing it in the background in idle time after the initial paint should be fine.

@adamziel I will explore this one and see if I can make any progress on it.

I started by adding the Vite PWA plugin and configuring it.
The next step is to enable offline support and ensure it works in development and production.

Playground loads only a part of WordPress on the first load. Other files are loaded as needed, we will need to find a way to preload all files for full offline support.

The offline mode mostly works when we shipping a full, zipped WordPress release. That's what the PR previewer does, e.g. try previewing this PR. We could add a separate offline mode very easily just by using that full zip bundle and caching it in the Service Worker.

After some discussion with @WordPress/playground-maintainers we create a list of tasks that should add offline and PWA support:

Should Playground use browser storage and support networking as the default option when installed?

If yes, it would be great for us to add a site switcher because we can't modify the url.

Should Playground use browser storage and support networking as the default option when installed?

It would be handy, yes, but it's not a blocker.

Flush cache when Playground updates

I wasn't able to get to this today but plan to look at this tomorrow if you don't tackle it first, @bgrgicak.

@adamziel has a PR for CLI offline support #1523

In a future iteration of offline support, we could add a background check to see if there were any updates to Playground and update the cache with the latest version of Playground.

Today this will work on reload, but mobile and desktop apps aren't usually reloaded.

I got offline support to work in the browser. Here is a list of all open PR that are required to make it work.

  • Download all WordPress assets on boot #1532
  • Generate a list of assets to cache for offline support #1573
  • Set service worker startup options with messages instead of query strings #1574
  • Cache Playground assets to enable offline support #1535

Please share any future comments in this PR