Skip to content

Commit

Permalink
Support offline mode after the first Playground page load (#1643)
Browse files Browse the repository at this point in the history
A set of bugfixes and enhancements for [PR 1535 – Cache Playground
assets to enable offline
support](#1535):

### Offline mode after a single page load

**Without this PR:**

When the service worker is first registered, it does not yet handle the
network requests triggered by the page that registered it. Files fetched
on the initial Playground load, like `wordpress-static.zip`, are not
cached. This means the offline mode won't work yet. You need to do a
full page reload, wait for another round of `fetch()`-es, and only then
you get cached assets and a functional offline mode.

**With this PR:**

Service Worker calls `self.clients.claim()` to start controlling the
Playground page when the service worker is initially registered. Static
assets are cached and offline mode works after the very first page load.

### Backfill static assets before the first paint

* If `wordpress-static.zip` is cached, it will be extracted during
Playground boot.
* If it's not cached, we'll boot and render Playground first, and only
then start downloading and extracting that file.

### Other smaller changes

* Simplified OfflineModeCache, used class methods (`function myFn(){}`
instead of instance methods (`myFn = () => {}`)

cc @bgrgicak

---------

Co-authored-by: Bero <berislav.grgicak@gmail.com>
  • Loading branch information
adamziel and bgrgicak authored Jul 24, 2024
1 parent 77a813f commit 26abb6b
Show file tree
Hide file tree
Showing 7 changed files with 1,850 additions and 1,607 deletions.
Loading

0 comments on commit 26abb6b

Please sign in to comment.