Repository navigation
Perf: shared admin-asset cache + hover window prewarming (opt-in), and the fixes that make the SW run on WordPress.com - #676
Conversation
Part one deletes the three pre-1.0 migration notes (async windowManager, AI comment-only, AI connectors), renumbers the docs index, and rewords every remaining sub-1.0 version stamp -- the architecture section loses its release-numbered title, and prose like "pre-0.9.6 behavior" now describes the behavior instead of the release. Part two is a point-by-point accuracy audit of all 101 doc pages against the source, fixing 133 confirmed discrepancies. The majors: hooks-reference had two script-registration claims and one permission-filter effect inverted; javascript-reference carried five localStorage keys under never-shipped os-* spellings, renamed os.os-theme.* hook strings, and an activity-channel catalog for channels that don't exist; files-on-desktop's nginx hardening snippet pointed at uploads/os-files/ while bytes live under the frozen uploads/desktop-mode-files/; native-windows-proposal named the legacy global wrongly in both directions; several examples could not work as pasted (a windowId comparison against the DOM-element prefix, a filter subscription under a renamed hook, imports from package subpaths that don't exist, a settings-tab id the validator rejects). Counts, defaults, tab orders, status labels, and anchors are trued up throughout, undocumented WindowManager methods joined the catalog, and scope notes now cover extension hooks and internal hook names. The wiki mirror re-syncs from docs/ on merge; conversion verified clean at 101 pages with zero unresolved links. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The root-scope SW now (opt-in) serves versioned admin static assets from one origin-wide Cache Storage bucket shared by the shell and every chromeless iframe window. Core-path assets and the load-scripts.php / load-styles.php concat responses are exact-URL cache-first (their ver= embeds the WP version); plugin/theme assets are stale-while-revalidate; uploads, unversioned URLs, HTML, REST and AJAX are never touched. Policy decisions live in src/pwa/sw-policy.ts (pure, unit-tested). The per-user opt-in is the "Shared asset cache (experimental)" toggle in OpenStation Preferences -> Features -> Beta features, persisted as adminAssetCacheEnabled; the openstation_pwa_admin_asset_cache filter takes that preference as its default and can force or veto site-wide. The value reaches the SW as a self.__OS_SW_CONFIG preamble injected by the PHP serve endpoint, so flipping it triggers a normal SW update with no URL change. The preamble also carries the real plugin URL, replacing the hardcoded pluginAssetBase() fallback for non-default layouts. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…s paths WordPress.com's nginx short-circuits paths with a static-file extension straight to the filesystem, so the virtual /openstation/sw.js route 404s before WordPress runs and the service worker has never been servable there (the extensionless manifest route was unaffected). Serve the same bytes at /?openstation_sw=1 — no extension, always reaches WordPress, and the script URL's / path grants root scope natively. Registration tries the pretty URL first and retries once with PwaConfig.swFallbackUrl; the foreign-SW guard recognizes both script URLs as OpenStation's own so a fallback-registered worker is not mistaken for a foreign SW on the next boot. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…e the click A sustained mouse hover on a dock tile is a strong predictor of the next click, and the document TTFB of an admin page (measured at 0.7-1.7s on production hosting) is the dominant cost of a window open. When the new "Prewarm windows on hover" Beta toggle is on, the dock asks the window manager to build that page's window hidden after a 180ms hover dwell; a later open() for the same page adopts it - reveal, stack, focus, os-window-opened - so the window appears with its document already loading or loaded. The speculative window lives in a single-slot cache OUTSIDE the stack, so session snapshots, the taskbar, dock peek and Alt-Tab never see it and no os-window-* event fires until adoption; discarding (TTL 45s, eviction by a newer prediction, URL mismatch at open) detaches the close callback first so teardown announces nothing. Boot cost is unchanged (+0 requests, +0.01% document, +0.05% gzipped assets vs baseline via bin/boot-cost.mjs) and the toggle defaults off. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… them The foreign-SW guard compared full script URLs, so a browser that installed the PWA before the portal-path move held a registration pointing at the old /desktop-mode/sw.js endpoint - which now serves an HTML page and can never self-update - and the guard mistook our own stale worker for another plugin's, refused to register, and stranded the user on a dead SW forever (observed live on a dev profile: a pwa-5 worker from the legacy path blocking every boot). Own script URLs are now matched as the current pretty URL, the extensionless fallback, or a legacy endpoint suffix (subdirectory installs included); a match means "ours but stale", and registering the current URL at the same scope replaces it - the exact recovery a dead worker needs. Genuinely foreign SWs still block with the same console warning. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Follow-up measurement: OpenStation vs classic wp-admin, head to headMeasured on openstation.blog after the PR was opened — same host, same browser session, warm cache on both sides. Classic admin reached via the plugin's own
The last row needs no feature flags and is the structural argument for the shell itself: classic wp-admin discards the document on every click, so revisiting a screen costs what visiting it cost the first time (server re-render + ~146 subresources re-evaluated). OpenStation keeps windows alive, so a revisit is a focus call — a ~1,000× difference on the most common interaction in the admin, true today with both toggles off. This PR's two features attack what remains, i.e. first opens of new screens: the shared asset cache takes the network out of the asset bill (~3.7 s → <0.5 s cold), hover prewarming takes the document wait out of the click (2,000 ms → 3.3 ms). Full protocol and raw data in the branch-side engineering report (Part 4). |
Correction to the head-to-head numbers above: the shell's cold start belongs in the comparisonThe previous comment compared classic cold document loads against OpenStation window opens measured inside an already-booted shell — an asymmetry, since the shell's own boot cost sat outside the table. Measured properly on openstation.blog, fresh navigations both sides:
OpenStation is ~2–2.8 s slower to first usable screen. That is structural, not a regression in this PR: the shell loads its own document and bundles and then loads a full wp-admin screen inside a window — two documents where classic loads one. Break-even on that boot, using measured inputs (classic ≈3.5 s cold dashboard / 2.8 s Settings / 1.6 s Tools; OpenStation 6.3 s boot, ~1.6 s new-screen open, 1.7 ms revisit):
Crossover is the first revisit; prewarming pulls it one interaction earlier. Honest scope: the shell wins any session with at least one revisit, and loses a single-screen visit-and-leave. None of this changes what this PR does — the two features and the two SW fixes are all measured deltas on top of whichever baseline you pick — but the comparison should not have been stated without the boot cost in it. Report Part 4 and the blog draft have both been corrected, and reducing that boot is the obvious next target. |
A window renders a real admin page with the admin bar suppressed -
show_admin_bar returns false and wp_admin_bar_render is removed from
in_admin_header - so #wpadminbar never reaches the DOM. WordPress and
the host still enqueued the bar's scripts and styles, which loaded,
parsed and executed against markup that does not exist, once per
window, every window.
Measured on a live WordPress.com install, one Settings window: 48.8 KB
across eight assets plus three cross-origin round trips, none of which
could do anything. The largest single one was our own os-admin-bar
toggle bundle at 17.7 KB, now guarded at its enqueue site.
The trim dequeues the whole admin-bar family (core's admin-bar, ours,
and the masterbar extras) because leaving one queued drags core's
handle back in as its dependency. Handles are dequeued, never
deregistered: a script that genuinely declares one as a dependency
still resolves it and keeps working. Filters
openstation_chromeless_trimmed_{scripts,styles} and the
openstation_chromeless_trimmed_assets action let sites extend or opt
out. No-op outside chromeless - the shell draws a real admin bar.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The dequeue pass alone left half the admin-bar family standing on a live install: WordPress.com's wpcom-notes-* handles enqueue after admin_enqueue_scripts has run, and core's admin-bar stylesheet rode back in as their dependency (WP_Dependencies::all_deps pulls a dequeued-but-registered handle back when something queued still needs it). print_scripts_array / print_styles_array run inside do_items() after every enqueue, dequeue and dependency walk, so they are the last word. Same handle list, so removing one member never strands another that depended on it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Added: windows no longer load the admin bar they never drawA window suppresses the admin bar entirely ( Measured on openstation.blog, one Settings window, before:
After: all eight gone (verified live — Two passes were needed, and the second one is the interesting part. Dequeuing at Handles are dequeued, never deregistered, so a script that genuinely declares one as a dependency still resolves it. The whole family ships in the defaults because leaving one member queued undoes the trim. Extensible via Honest sizing: 48.8 KB out of ~5 MB of JavaScript that this (Gutenberg-plugin-heavy) site loads per window, so the wall-clock effect is inside this host's run-to-run noise — the win is the bytes, the parse/execute work, and the three cross-origin round trips, on every window a user ever opens. 10 new PHPUnit tests cover the defaults, both passes, the shell no-op, registration survival, and the filters. |
…n the editor WordPress's emoji detection script tests the browser against the newest Unicode emoji set and, when anything is missing, pulls in wp-emoji-release.min.js (Twemoji, 22 KB) to swap those characters for images. It is a real polyfill rather than dead code - measured loading on current Chrome inside a window, because browsers routinely lag the newest emoji. Dropping it in a window is still right, and Core sets the precedent itself: wp-admin/edit-form-blocks.php removes this exact action on the block-editor screen. The only loss is that a very new emoji in admin content renders with the OS glyph instead of a Twemoji image, and the shell hosting these windows already requires service workers, custom elements, ES2020 and :has() - a browser clearing that bar does not need help drawing emoji. Removal runs on admin_init because wp_enqueue_emoji_styles rides admin_enqueue_scripts at the default priority and has already fired by the time the handle trim runs at PHP_INT_MAX. Filterable via openstation_chromeless_trim_emoji. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Emoji polyfill dropped in windows too — plus a correctionCorrection first. My earlier note labelled the emoji script "never used in admin". That was wrong, and our own measurement disproves it: Dropping it in a window is still right, and Core sets the precedent itself: Removal runs on Verified live on openstation.blog — window vs shell, same page load:
Page renders, its form works, zero console errors. Cumulative effect of this trim work, per window: scripts 109 → 100, stylesheets 19 → 18, JavaScript 5,063 KB → 4,892 KB, |
…er window The bridge lived in a PHP nowdoc and was printed inline into every chromeless window: ~125 KB of unminified JavaScript, comments and all, landing in the HTML document. A document is the one asset no cache can help with, so that cost was paid in full on every window open, forever. The code moves verbatim to src/chromeless-bridge.js and builds to assets/js/chromeless-bridge[.min].js (34.5 KB minified, 10.5 KB gzipped) - fetched once, then served from the browser and the shared service-worker cache for every later window. The four values that genuinely vary per request (menu payload, menu signature, content identity, soft-reload rules) are attached as a small inline `before` block on window.__osChromelessData, replacing the str_replace pass over placeholder comments. in_footer plus a `before` inline block reproduces the old emission exactly: data defined, then the bridge running, at the same point in the document, with no defer/async that would move it after the page's own footer scripts. Also hardens the enqueue: WP_Dependencies::enqueue() silently no-ops on an unregistered handle, and plugins that rebuild WP_Scripts wholesale are a documented shape (see asset-guard.php). The bridge is the one script a window cannot do without, so it re-registers if the handle has gone missing. Tests that assert on bridge behaviour now read the source that builds into the bundle rather than slicing it out of the nowdoc. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The chromeless bridge is a bundle now — the window document halvedInvestigating "what else can we trim from a window?" turned up the biggest item in the page, and it was ours.
The code moves verbatim to Measured live on openstation.blog, same Settings window:
Bridge verified functioning live: bundle served from cache ( Re-ran the Settings → Writing → Reading × 3 journey (the one that previously came out a tie): total 20.7 s → 19.4 s, median per screen 2.77 s → 2.30 s (−17%). It is now level with classic wp-admin's 19.4 s rather than behind it. Honest framing: halving the document moved the total by ~6%, because the bytes were never the expensive part — waiting for the server is. Every screen is simply delivered in half the bytes now. One hardening that came out of the test suite: Tests that assert on bridge behaviour now read the source that builds into the bundle rather than slicing it out of the nowdoc — 5 test classes updated. Full suites green: 4,916 JS / 2,435 PHP, phpcs, typecheck, lint, build. |
|
@claude can you review this? |
|
Claude finished @AllTerrainDeveloper's task in 3m 51s —— View job Reviewing this PR
Note on process: this branch is a shallow checkout with no merge-base against OverallThis is a well-engineered PR — the policy/effect split ( 1. Dead condition in if ( ! item.url || ( item.windowId && ! item.url ) ) {The second clause ( 2. 3. Stale top-of-file comment in 4. Extensionless SW fallback endpoint matches on query alone ( Things done well, worth calling out
Nothing here blocks merging — these are polish-level notes on an otherwise solid, well-tested change. |
…stale docblock Four review findings, three of them small: 1. dock.ts hover-prewarm guard: `! item.url || ( item.windowId && ! item.url )` reduced to `! item.url`. The second clause could never independently be true - the `||` short-circuits when `! item.url` holds, and the clause is false otherwise. A native-window tile is exactly the `! item.url` case, so the check is unchanged in effect; the comment now says that instead of the code implying it. 2. chromeless-bridge.js now has ESLint coverage via an override (espree, no type-aware rules), and `npm run lint` includes it. The ES5-style rules are off for this file: it deliberately runs as ES5 inside a real wp-admin document, and auto-fixing 3,500 lines of a verbatim lift would rewrite working code for taste - `no-var` in particular changes binding semantics around closures. Enabling the rest surfaced no undefined names and no unused bindings; the four real findings are fixed here (a shadowed `ev`, a shadowed loop index, a `var` shared across two mutually-exclusive branches, and a useless `return`). The TypeScript conversion stays a follow-up, and the file header now says so rather than leaving the gap implicit. 3. The extensionless SW endpoint matched `?openstation_sw=1` on any path. It is now pinned to the site root - the one URL openstation_pwa_sw_fallback_url() builds and the only one registration requests. Harmless before (the handler streams a static file and reflects nothing), but wider than the documented contract, and a worker's scope comes from the path it is served from. 4. The bridge-links test's top docblock still described the interceptor as "emitted from a PHP heredoc", contradicting the corrected comment below it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Two opt-in performance features (both default off, behind OpenStation Preferences → Features → Beta features) plus two service-worker bug fixes that ride along — one of which makes the SW run on WordPress.com hosting for the first time ever. Everything below was measured live on openstation.blog (WordPress.com production hosting, real network) with in-page instrumentation; the full protocol and raw run data live in the branch-side engineering report.
What ships
adminAssetCacheEnabled, Experimental). The root-scope SW serves versioned admin assets — Core CSS/JS, theload-scripts.php/load-styles.phpconcat blobs, plugin/theme assets carrying?ver=— from one origin-wide Cache Storage bucket shared by the shell and every window's chromeless iframe. Core paths are exact-URL cache-first (theverparam embeds the WP version — the same immutability contract Core expresses by serving the loaders with a one-yearCache-Control); plugin/theme assets are stale-while-revalidate so unversioned file edits self-heal on the next load; uploads, HTML, REST, AJAX and unversioned URLs are never touched. Bucket capped at ~500 entries (FIFO), version-keyed, flushed on every SW release. Policy is pure + unit-tested (src/pwa/sw-policy.ts). The per-user toggle is the filter default;openstation_pwa_admin_asset_cachecan force or veto site-wide.windowPrewarmEnabled, Experimental). A 180 ms mouse dwell on a dock tile builds that page's window hidden — the iframe loads while the user decides — and the real click adopts it: reveal, stack, focus,os-window-openedfired exactly then. The speculative window lives in a single slot outside the window stack, so sessions, taskbar, dock peek and Alt-Tab never see it; unclaimed prewarms self-destruct after 45 s with the close callback detached (no phantom events). Excluded by design: native windows, cross-origin URLs, native-remapped URLs..js-looking paths to the filesystem, so the virtual/openstation/sw.jsroute 404'd before WordPress executed — silently, on every WP.com install. The same bytes are now also served at the extensionless/?openstation_sw=1(path/grants root scope natively), and registration retries withPwaConfig.swFallbackUrlon failure. Verified live: openstation.blog registered through the fallback on its own, first SW execution ever on this host class./desktop-mode/sw.js, which now serves HTML and can never self-update) was stuck on a dead worker, observed live. Own legacy script URLs are now recognized and replaced by registering the current URL at the same scope; genuinely foreign SWs still block.Measurements (openstation.blog, production)
load-styles.phpconcat blob (PHP-generated per miss)load-scripts.phpblobsbin/boot-cost.mjs, baseline vs branch)Integrity: SW-served bodies were byte-identical to network fetches in every comparison run (core assets, plugin assets, and concat blobs). Cross-window sharing observed directly: a first-ever
tools.phpopen started with 38/114 assets already bucketed by a different page's window, andplupload.min.jsreturned in 2 ms on a nominally cold fetch because another page had cached it.Worst case: parity — and why that trade is worth it
For users who never opt in, the worst case is nothing: measured +0 requests and +0.01% document on boot, zero behavior change. For opted-in users, the worst case is parity, not regression: on a warm browser against well-configured hosting, steady-state reopens measured 1,589 ms (cache on) vs 1,657 ms (off) — inside run-to-run noise, because the browser's own HTTP/memory cache already absorbs a warm steady state and parse/execute dominates. No measured scenario got slower than baseline. The bounded costs that do exist: a one-time ~400 ms populate pass on the first open after enabling (1,979 vs 1,589 ms, then gone); one speculative server-side page render per hover-intent (single slot, 45 s TTL) — the explicit trade the prewarm toggle buys; and a plugin that edits files without bumping its version serves one stale load before stale-while-revalidate self-heals, which is no worse than any far-future-cache host already treats such plugins.
The upside side of that trade is every case where the browser cache doesn't help — first visit of the day, evicted disk cache, hard reload, high-latency links, offline — where the measured per-request delta is two orders of magnitude, and window opens go from seconds to milliseconds on a prewarm hit. Parity in the best-case scenario, large wins in every degraded scenario, zero cost when dark: that is the definition of a worthwhile opt-in.
One thing this PR explicitly does not fix, now that it is measured: the shell's ~6.3 s cold boot (vs 2.6–4.4 s for a classic admin page). Prewarming hides per-window document cost after boot; it does nothing for boot itself, and the asset cache is cold on a first-ever visit by definition. That number is the obvious next target and is called out in the report rather than left implied.
Testing
sw-policyclassification matrix, SW-register fallback + legacy-recognition, window prewarm lifecycle (hidden mount, adoption, URL-mismatch discard, silent teardown, single slot, TTL). Full suite: 4,916 passed.npm run lint,lint:php,typecheck,buildall green;bin/boot-cost.mjsbefore/after diff attached above.page-optimizenormally replaces core concat).Docs
docs/pwa.md(caching policy table, shared-cache section, WP.com hosting note, fallback URL),docs/hooks-reference.md(new filter + helpers),docs/javascript-reference.md(windowManager.prewarm()/discardPrewarmed(), bothgetOsSettings()keys) — all updated in the same commits as the code.🤖 Generated with Claude Code