Home › Web performance › Web performance (Core Web Vitals) rules

Web performance (Core Web Vitals) rules

Cursor rules for keeping web apps fast: Core Web Vitals (LCP, INP, CLS), bundle size, images, and measuring first.

CursorWeb performance

How to use

Save this as .cursor/rules/performance.mdc in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

.cursor/rules/performance.mdcDownload  
---
description: Use when working on page speed, bundle size, slow rendering, or Core Web Vitals.
alwaysApply: false
---

# Web performance

## Measure first
- Get a baseline before changing anything: Lighthouse (`npx lighthouse <url> --only-categories=performance`), the browser Performance panel, or field data (CrUX/RUM). Report before/after numbers.
- Targets: LCP < 2.5s, INP < 200ms, CLS < 0.1 on a mid-range mobile profile.

## LCP
- Find the LCP element. Serve it as an optimized image (AVIF/WebP, correct `sizes`/`srcset`) with `fetchpriority="high"`; never lazy-load it.
- Avoid render-blocking scripts and CSS; preload critical fonts, use `font-display: swap`.
- Server-render or statically generate above-the-fold content.

## INP
- Break up long tasks (> 50ms): defer non-urgent work (`scheduler.yield()` or `setTimeout`), debounce input handlers, move heavy work to a Web Worker.
- Avoid re-rendering large trees on each keystroke (virtualize long lists).

## CLS
- Set `width`/`height` or `aspect-ratio` on images, video, ads and embeds. Reserve space for late content; don't insert banners above existing content.

## Bundle
- Check size with the bundler analyzer. Code-split routes and heavy components (`import()`), and replace heavy dependencies (e.g. moment -> `Intl`/date-fns).
- Third-party scripts load `async`/`defer` or after interaction.

## Don't
Don't micro-optimize without a measured problem, or trade correctness for speed.

Related rules

Astro content site rules

Cursor rules for Astro 5 sites with content collections, islands, and zero-JS-by-default pages.

CursorAstro

Chrome extension (Manifest V3) rules

Cursor rules for building Manifest V3 browser extensions with TypeScript and minimal permissions.

CursorChrome extensions

Cloudflare Agents SDK rules

Cursor rules for stateful AI agents on Cloudflare (agents package): Durable Object state, SQL, scheduling, and WebSockets.

CursorCloudflare Workers / Hono

Convex backend rules

Cursor rules for Convex backends: schema, validated queries/mutations/actions, indexes, and auth checks.

CursorConvex

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.