Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply 62 React and Next.js performance optimization rules from Vercel Engineering
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/rendering-resource-hints.md
1---2title: Use React DOM Resource Hints3impact: HIGH4impactDescription: reduces load time for critical resources5tags: rendering, preload, preconnect, prefetch, resource-hints6---78## Use React DOM Resource Hints910**Impact: HIGH (reduces load time for critical resources)**1112React DOM provides APIs to hint the browser about resources it will need. These are especially useful in server components to start loading resources before the client even receives the HTML.1314- **`prefetchDNS(href)`**: Resolve DNS for a domain you expect to connect to15- **`preconnect(href)`**: Establish connection (DNS + TCP + TLS) to a server16- **`preload(href, options)`**: Fetch a resource (stylesheet, font, script, image) you'll use soon17- **`preloadModule(href)`**: Fetch an ES module you'll use soon18- **`preinit(href, options)`**: Fetch and evaluate a stylesheet or script19- **`preinitModule(href)`**: Fetch and evaluate an ES module2021**Example (preconnect to third-party APIs):**2223```tsx24import { preconnect, prefetchDNS } from 'react-dom'2526export default function App() {27prefetchDNS('https://analytics.example.com')28preconnect('https://api.example.com')2930return <main>{/* content */}</main>31}32```3334**Example (preload critical fonts and styles):**3536```tsx37import { preload, preinit } from 'react-dom'3839export default function RootLayout({ children }) {40// Preload font file41preload('/fonts/inter.woff2', { as: 'font', type: 'font/woff2', crossOrigin: 'anonymous' })4243// Fetch and apply critical stylesheet immediately44preinit('/styles/critical.css', { as: 'style' })4546return (47<html>48<body>{children}</body>49</html>50)51}52```5354**Example (preload modules for code-split routes):**5556```tsx57import { preloadModule, preinitModule } from 'react-dom'5859function Navigation() {60const preloadDashboard = () => {61preloadModule('/dashboard.js', { as: 'script' })62}6364return (65<nav>66<a href="/dashboard" onMouseEnter={preloadDashboard}>67Dashboard68</a>69</nav>70)71}72```7374**When to use each:**7576| API | Use case |77|-----|----------|78| `prefetchDNS` | Third-party domains you'll connect to later |79| `preconnect` | APIs or CDNs you'll fetch from immediately |80| `preload` | Critical resources needed for current page |81| `preloadModule` | JS modules for likely next navigation |82| `preinit` | Stylesheets/scripts that must execute early |83| `preinitModule` | ES modules that must execute early |8485Reference: [React DOM Resource Preloading APIs](https://react.dev/reference/react-dom#resource-preloading-apis)86