5252 * While this strategy enables fast load times and an offline experience, it also
5353 * creates a substantial challenge.
5454 *
55- * When a new Playground version is deployed, all the clients will load an old
56- * version of the `remote.html` file on their next visit. Unfortunately, that old
57- * `remote.html` file contains hardcoded references to assets that may not be
58- * cached and no longer exist in the new webapp build.
55+ * When a new Playground version is deployed, clients may load an old entry
56+ * document such as `remote.html` or `api.html`. That document contains
57+ * hardcoded references to assets that may no longer exist in the new build.
5958 *
60- * To solve this problem, we use the **Network first** strategy when `remote.html`
61- * is requested . This introduces a small network overhead, but it guarantees loading
62- * the most recent version of `remote.html` and all the referenced assets.
59+ * To solve this problem, we use the **Network first** strategy for entry
60+ * documents . This introduces a small network overhead, but guarantees loading
61+ * the most recent document and all its referenced assets.
6362 *
6463 * Similarly, we use the **Network first** strategy for the `/` path. This is
6564 * useful in situations where the user didn't visit Playground in a while,
6665 * they have a stale version of the `/` route cached, and they open Playground.
6766 * If we loaded the cached version, they'd see the old Playground website on their
6867 * first visit and then the new Playground website only on their second visit.
6968 *
70- * There's still a small window of time between loading the remote.html file and
71- * fetching the new assets when a new deployment would break the application.
69+ * There's still a small window between loading an entry document and fetching
70+ * its assets when a new deployment would break the application.
7271 * This should be very rare, but when it happens we provide an error message asking
7372 * the user to reload the page.
7473 *
@@ -365,7 +364,8 @@ self.addEventListener('fetch', (event) => {
365364 }
366365
367366 /**
368- * Always fetch the fresh version of `/remote.html` and `/` from the network.
367+ * Always fetch fresh versions of `/remote.html`, `/api.html`, and `/` from
368+ * the network.
369369 *
370370 * This is the secret sauce that enables seamless upgrades of the
371371 * running Playground clients when a new version is deployed on
@@ -374,13 +374,14 @@ self.addEventListener('fetch', (event) => {
374374 * ## The problem with deployments
375375 *
376376 * App deployments remove all the static assets associated with the
377- * previous app version. Meanwhile, the remote.html file we've cached
378- * for offline usage still holds references to those assets.
377+ * previous app version. Meanwhile, cached entry documents still hold
378+ * references to those assets.
379379 *
380- * If we just loaded the cached remote.html file , the site would crash
380+ * If we just loaded a cached entry document , the client would crash
381381 * with seemingly random errors.
382382 *
383- * Instead, we fetch the most recent version of remote.html from the network.
383+ * Instead, we fetch the most recent version of each entry document from
384+ * the network.
384385 * It references the static assets that are now available on the server and
385386 * should work just fine.
386387 *
@@ -392,7 +393,11 @@ self.addEventListener('fetch', (event) => {
392393 * https://github.com/WordPress/wordpress-playground/issues/1821 for more
393394 * details.
394395 */
395- if ( url . pathname === '/remote.html' || url . pathname === '/' ) {
396+ if (
397+ url . pathname === '/remote.html' ||
398+ url . pathname === '/api.html' ||
399+ url . pathname === '/'
400+ ) {
396401 event . respondWith ( networkFirstFetch ( event . request ) ) ;
397402 return ;
398403 }
0 commit comments