dataconnect/demo

EX-02 · Navigation · Browser platform

View transitions & prerendering

Two browser features make an ordinary multi-page site feel like an app, with no client-side router. Speculation rules prerender the next page while you hover a link, and cross-document view transitions animate from one real page load to the next. Every page on this site has both switched on.

Transitions
@view-transition
Prerendering
speculationrules
JavaScript needed
None
Your browser
Needs JavaScript to check

Try it

Hover a swatch for a moment, then click. The page is already rendered when you arrive, and the colour chip grows into its header. Step through the swatches with the arrows, then come back and compare the log below. Switch either feature off to feel the difference. The switches apply to the whole site until you turn them back on.

View transitions On
Prerendering On

This navigation

First paint is measured from the moment you navigated. A prerendered page painted before you clicked, so it reads 0 ms.

Recent navigations

This page, shared in Discord

dataconnectToday at 3:42 PM
Exhibit 02 · Real page loads that animate like an app, with pages prerendered before you click. No client router.
Exhibit 02 mark
Recorded from this site in Chromium · 10 s loop ·
Approximation of Discord's dark theme. Times shown in UTC until your browser localises them.

The card for this page is design D6 from Exhibit 01. Its media gallery holds an animated GIF of this site's own transitions, which Discord plays inline. A video in a gallery wouldn't autoplay.

The GIF is a real recording. scripts/record-gif.mjs drives Chromium through the swatches with every transition slowed 10×, keeps the frames Chrome actually presented, and retimes them to real speed.

How this site wires it

1 · Opt in on both pages. One at-rule in a stylesheet every page loads. Reduced-motion users get plain navigations.
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
}
2 · Prerender same-site links. This exact rule set is in the head of every page. moderate starts on hover or pointer-down.
<script type="speculationrules">
{
  "prerender": [
    {
      "where": {
        "and": [
          {
            "href_matches": "/*"
          },
          {
            "not": {
              "href_matches": "/api/*"
            }
          }
        ]
      },
      "eagerness": "moderate"
    }
  ]
}
</script>
3 · Name the shared element on both pages. Same name, one per page, and the browser morphs one box into the other.
<!-- /view-transitions -->
<span style="view-transition-name: swatch-oxide">

<!-- /view-transitions/oxide -->
<div style="view-transition-name: swatch-oxide">

Field notes

  1. Both pages must opt in

    A cross-document transition only runs when the old and new page are same-origin and both have @view-transition { navigation: auto; }. That's why the switch above has to apply to the whole site.

  2. One name per page

    If two elements on a page share a view-transition-name, the browser skips the whole transition. The tray names each chip after its swatch for that reason.

  3. Prerendered pages run early

    A prerendered page runs its scripts before anyone sees it. Check document.prerendering and wait for prerenderingchange before counting a view. The log here waits the same way.

  4. The server can tell

    Speculative fetches carry Sec-Purpose: prefetch;prerender. The "Server saw" row above shows the header the Pages Function received for this page.

  5. Keep side effects out

    The rules exclude /api/*, and the switches are form POSTs, which are never prerendered. Don't point speculation rules at a URL that changes something when it's fetched.

  6. Eagerness is a budget

    moderate waits for a short hover or a pointer-down, so prerenders follow intent. eager would prerender every matching link straight away, and browsers cap how many prerenders they keep.

  7. Unsupported means ordinary

    Browsers without these features ignore the rule and the script and simply navigate. Nothing breaks, so there's no feature detection to write.

  8. Mind the back button

    Back and forward usually restore from the back/forward cache instead, which is even faster than a prerender. The log shows these as their own kind of arrival.