协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
enhance-web-instant-nav【开发与工程】Instant in-site navigation: Speculation Rules, View Transitions, bfcache, 103 Early Hints. Use when "instant navigation", "prerender", "early hints", "back button reloads", or "second page is slow". First-load CWV → audit-performance.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Surface router:
/uiux. You are here:enhance-web-instant-nav.
Degree of freedom: MIXED. Which pages to speculate [HIGH freedom];
the exclusion list, Sec-Purpose handling, and re-measure [LOW freedom — run exactly].
Applies to MPAs and Next.js App Router (server-rendered routes). Pure SPA routing → use the framework's prefetch API; Speculation Rules are per-document.
Observe: blog; first-page LCP 1.9 s, next-article LCP 2.8 s; back button reloads (
unloadin analytics). Rank: "next article" 61% of sessions → prerender moderate; category links → prefetch moderate. Guard:/logout,/account/*,?utm_*excluded; server returns early onSec-Purpose. Ship: rules block +pagehideswap +document.prerenderingguard in the GA loader. Re-measure: next-article LCP 0.3 s (activation), bfcache green, no analytics double-count.
Sec-Purpose contains prefetch, skip counters/side effects; return normal HTMLdocument.prerendering === false or on prerenderingchangeunload listeners; never set Cache-Control: no-store on HTML unless legally requiredweb-vitals/attribution onLCP on the second page in a session; record p75curl -sv <url> 2>&1 | grep "< HTTP" — is a 103 emitted today?# Field: CrUX / PSI p75 for origin + top URLs
npx @lhci/cli autorun --config=lighthouserc.json
curl -sv https://example.com/ 2>&1 | grep -E "< HTTP/.* 103"
Baseline (adjust where to the site's IA):
<script type="speculationrules">
{
"prefetch": [{
"where": { "and": [
{ "href_matches": "/*" },
{ "not": { "href_matches": ["/logout", "/account/*", "/cart*", "/checkout*", "/api/*"] } },
{ "not": { "selector_matches": "[rel~=nofollow], .no-prefetch" } }
]},
"eagerness": "moderate"
}],
"prerender": [{
"where": { "href_matches": "/posts/*" },
"eagerness": "moderate"
}]
}
</script>
conservative (pointer/touch down) → moderate (desktop: hover 200 ms or pointerdown; mobile: viewport heuristics) → eager (Chrome 143+: desktop hover 10 ms, mobile viewport heuristics) → immediate (as soon as the rules load). Left unset, list (urls) rules default to immediate and document (where) rules to conservative, so set moderate explicitly. immediate on document rules is allowed but speculates on every matching link; use it with care."expects_no_vary_search": "params=(\"utm_source\" \"utm_medium\")" or exclude ? URLs<Link> prefetch for RSC payloads; add the block in app/layout.tsx via a raw <script>. On Next.js 16.3+ evaluate Instant Navigations first (opt-in: cacheComponents: true + partialPrefetching: true in next.config); if it covers the case, skip prerender rules and keep only prefetch.Syntax depth: references/speculation-rules.md.
unload → pagehide; beforeunload only while unsaved input existspagehide; reopen on pageshow if event.persistedCache-Control: no-store from HTML (keep it on APIs)Blocker list: references/bfcache-blockers.md.
@view-transition { navigation: auto; }
@media (prefers-reduced-motion: reduce) { @view-transition { navigation: none; } }
.hero-img { view-transition-name: hero; }
view-transition-name unique per document or the transition abortsprefers-reduced-motion is required (pairs with audit-accessibility)Link: </hero.avif>; rel=preload; as=image; fetchpriority=high, Link: <https://cdn.example>; rel=preconnectres.writeEarlyHints({ link: [...] }); else CDN configreferences/early-hints.mdSec-Purpose — grep itaudit-performance; JS weight → audit-bundle-size<script type="speculationrules"> blockaudit-performance — first-load CWV / loading priorityaudit-bundle-size — JS weight; don't double-prefetchaudit-accessibility — reduced-motion for View Transitionsenhance-pwa — service worker vs speculation / bfcache