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.

More: all Web performance rules · all Cursor rules

Related rules

Universal vibe-coding guardrails

Always-on Cursor rules that keep any AI agent careful: plan first, small diffs, verify, never fake it.

CursorAny stack

Jest testing rules

Cursor rules for Jest 30 test suites in TypeScript: structure, mocking boundaries, timers, and async tests.

CursorTesting

Playwright end-to-end testing rules

Cursor rules for Playwright Test (TypeScript): resilient locators, web-first assertions, fixtures, and no flaky waits.

CursorTesting

Safe refactoring rules

Cursor rules for behavior-preserving refactors: small steps, tests first, no mixed feature changes, and clear diffs.

CursorAgent workflows

Web accessibility (WCAG 2.2) rules

Windsurf rules for building accessible web UIs to WCAG 2.2 AA: semantics, keyboard, focus, contrast, and testing.

WindsurfAccessibility

Code review Copilot instructions

Copilot instructions focused on pull request review: what to flag, severity labels, and how to word comments.

GitHub CopilotAgent workflows

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.