Skip to content

Project Scoping: Offline Support #1600

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

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions projects/in-progress/2024-07-11-offline-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
### Problem we are solving

Playground can't be used while offline.

### Solution

We can make Playground available offline after visiting the Playground.WordPress.net website or installing it as a PWA.

### Project Goal

Allow anyone to use WordPress while offline without a complicated setup.

### Use Cases

This will enable building offline first WordPress apps.

Apps like SPAs and mobile apps that use WordPress as a backend will be able to embed the entire backend in the app and not rely on a server.

### Limitations

We will need to limit the switching of PHP and WordPress versions while offline to ensure users don't download too much data on the first load.

## Project plan

We plan to start by adding PWA support to Playground which will allow users to install it as an app and use it while online.

After that, we need to ensure all assets are available after the first load which will make Playground available offline.

Once Playground works offline we need to restrict some features like version switching while offline and add tests to ensure offline keeps working long-term.

## Development

- [x] [PWA support](https://github.com/WordPress/wordpress-playground/pull/1086)
- [ ] [Separate manifest.json files for each environment](https://github.com/WordPress/wordpress-playground/pull/1615)
- [x] [Backfill remote WordPress assets](https://github.com/WordPress/wordpress-playground/pull/1532)
- [ ] Backfill Playground assets
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are two ways assets can be backfilled.

  • When the site requests an asset we can cache it using a service worker.
  • We can cache files from a static list when the Playground boots.

When the site requests an asset we can cache it using a service worker.

This method is preferred because it avoids maintaining a list of files to download.
The challenge is that it can start only after the service worker loads.

To start loading data as early as possible we will move registerServiceWorker to run before spawnPHPWorkerThread in packages/playground/remote/src/lib/boot-playground-remote.ts.

We can cache files from a static list when the Playground boots.

This could happen at the same time when we download WordPress assets.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To start loading data as early as possible we will move registerServiceWorker to run before spawnPHPWorkerThread in packages/playground/remote/src/lib/boot-playground-remote.ts.

I did this in #1606 and can confirm that it will allow us to load WordPress and PHP assets without backfilling. This will make the implementation simpler because the backfill script won't need to know what's the current PHP and WP version.

Most other items will need to be backfilled.

Here is an example of how items load with #1606

First load

/favicon.ico
/worker-thread-5bd5ae4a.js
/assets/sqlite-database-integration-fd6f4063.zip
/assets/wp-6.5-264f1631.zip
/assets/php_8_0-a8925787.js
/assets/php_8_0-3584e351.wasm
/src/fonts/1258fcda79d43bef/inter_Inter-Regular.woff
/src/fonts/f86c32ba0f42a842/inter_Inter-SemiBold.woff
/src/fonts/8efb053b450b4a72/inter_Inter-Medium.woff
/src/fonts/62c967bbd6d11106/inter_Inter-Light.woff
/avatar/e6d67fed862c439aa6e911ce49c7857d

Second load

Cache miss

/gtag/js
/assets/index-9b5e396e.js
/assets/modulepreload-polyfill-3cfb730f.js
/assets/preload-helper-cf010ec4.js
/assets/index-d60708af.css
/assets/main-7bf730a2.css
/g/collect
/remote.html
/assets/wordpress-c3703a25.js
/assets/remote-b5d5f2da.css

Cache hit

/favicon.ico
/worker-thread-5bd5ae4a.js
/assets/sqlite-database-integration-fd6f4063.zip
/assets/wp-6.5-264f1631.zip
/assets/php_8_0-a8925787.js
/assets/php_8_0-3584e351.wasm
/src/fonts/1258fcda79d43bef/inter_Inter-Regular.woff
/src/fonts/f86c32ba0f42a842/inter_Inter-SemiBold.woff
/src/fonts/8efb053b450b4a72/inter_Inter-Medium.woff
/src/fonts/62c967bbd6d11106/inter_Inter-Light.woff
/avatar/e6d67fed862c439aa6e911ce49c7857d
/g/collect

- [x] [Generate a list of assets to cache](https://github.com/WordPress/wordpress-playground/pull/1573)
- [ ] [Cache Playground assets to enable offline support ](https://github.com/WordPress/wordpress-playground/pull/1535)
- [x] [Add cache version number](https://github.com/WordPress/wordpress-playground/pull/1541)
- [x] [Set web worker startup options with messages instead of query strings](https://github.com/WordPress/wordpress-playground/pull/1574)
- [ ] Cache Playground static fetch requests
- [ ] Offline e2e tests
- [ ] Ensure tests run on a preview version of Playground
- [x] [Limit features while offline](https://github.com/WordPress/wordpress-playground/pull/1607/files)

## Notes

- [Prototype](https://github.com/WordPress/wordpress-playground/pull/1483)
- [Project issue](https://github.com/WordPress/wordpress-playground/issues/133)
Loading