Repository navigation
Play page: no layout shift, engine sooner, / → /play prerendered - #12
Merged
Merged
Conversation
- The play page's markup is the game's first frame: both charts, the ship dock and the status line are drawn at build time (Chart.astro), so nothing moves when the script and engine arrive (mobile CLS 0.43 → 0). A saved fleet is shown before the engine has loaded; Random and Start wait for it. - The engine is preloaded with the page and compiled while it downloads (instantiateStreaming) instead of fetched after the script ran. - Hashed assets under /_astro/ are cached for a year, immutable; they were revalidated on every page view. - Stylesheets are inlined: no request holds up the first paint. - Speculation rules: Chromium prerenders a page of the site when a link to it is hovered (or pressed), and fetches /play's page ahead; elsewhere, the page and engine are fetched on the first sign of heading for /play. Measured on a throttled connection (4 Mbit/s, 100 ms), click on Play to a playable board: about 1150 ms before, 420 ms now (190 ms with a saved fleet), without counting the prerender, which headless Chrome does not do. Screenshots of /play and / are pixel-identical to before.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Switching from
/to/playwas slow and the page jumped. The page looks exactly the same as before; it just loads faster and holds still.What was wrong
/_astro/*files withmax-age=0, must-revalidate, so every page view rechecked the CSS, fonts, JS and wasm with the server.Changes
Chart.astro,Game.astro): both charts, the dock, the shot counters and the hint are built into the HTML, andgame.tshooks into that markup instead of creating it. A tiny inline script sets the status line before the first paint. For a returning player it shows "Your fleet is ready". For a new player it reserves a hidden line of the right height. A saved fleet appears and can be moved before the engine has loaded. Random and Start battle wait for the engine if they're pressed before it's ready.<link rel="preload">for the wasm, andWebAssembly.instantiateStreamingso it compiles while it downloads. If the server sends the wrong content type, it falls back to the old non-streaming way.vercel.json:/_astro/*getsCache-Control: public, max-age=31536000, immutable.build.inlineStylesheets: "always"), so no stylesheet request delays the first paint.Base.astro): Chromium prerenders a site page when you hover over a link to it or press it, so the script and engine are already running when you arrive./play's HTML is fetched ahead as soon as a link to it is on the page, and download links are skipped. Safari and Firefox don't support this, so a small script fetches/playand the engine into the cache the first time you hover, focus or touch a Play link.offline.mjsremoves the engine preload and the fetch-ahead scripts frombroadside.html, since they mean nothing in a file opened from disk.The wasm build itself is unchanged. I tried
opt-level2 ands: they save 20–45 KB with brotli, but make the engine 2–3× slower per move (mean 20 ms at opt 3, 36 ms at opt 2, 61 ms at opt s), so opt-level 3 stays.Measured
Headless Chrome, throttled to 4 Mbit/s with 100 ms latency, on a local server that sends the same headers as
vercel.jsonwith brotli. Each test loads/, hovers Play, clicks it and times until the board is playable./play, mobile 390 px/play, desktopThese numbers leave out the prerender, because Chrome turns prerendering off while automation tools are connected (
PrerenderingDisabledByDevTools). The rules are valid and Chrome does start them on hover. With a real browser the switch to/playshould be instant.The first desktop run of each batch was a one-off at ~1170 ms; later runs were ~420 ms.
Checks
npm run buildpasses, including the offline file (1.81 MB).npm run check: 0 errors, 0 warnings, 0 hints.cargo clippy --all-targetsis clean andcargo testpasses (no Rust was changed).main:/play(desktop and mobile, light and dark, before and after picking up a ship) and/are identical.broadside.htmlplays a full game