Skip to content

Conversation

@adamziel
Copy link
Collaborator

@adamziel adamziel commented Jul 23, 2024

A set of bugfixes and enhancements for PR 1535 – Cache Playground assets to enable offline support:

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

@adamziel adamziel changed the title Refactor OfflineModeCache and await the static assets backfilling if they're in cache Support offline mode after the first Playground page lod Jul 23, 2024
@adamziel adamziel changed the title Support offline mode after the first Playground page lod Support offline mode after the first Playground page load Jul 23, 2024
@bgrgicak bgrgicak merged commit 26abb6b into add/fetch-caching Jul 24, 2024
@bgrgicak bgrgicak deleted the add/fetch-caching-depend-on-cached-status branch July 24, 2024 04:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants