frontend-performance-optimization

A measurement-led process for finding and improving slow or unresponsive web pages. It covers page loading, browser rendering, JavaScript execution, memory use, and the size of the files sent to the browser.

In plain words
What is it for?
It helps diagnose slow loading, long blank screens, laggy interactions, poor Core Web Vitals such as LCP, FID, and CLS, oversized builds, excessive requests, repeated rendering, memory leaks, and slow large-list rendering.
Why use it?
It prevents developers from making untested performance changes by requiring data such as Lighthouse reports, browser recordings, bundle analyses, or network timings before recommending fixes.

Skill for Claude CodeCodexCursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/programmeranthony/expert-coding-harness/frontend-performance-optimization
Any agent
npx skills add ProgrammerAnthony/Expert-Coding-Harness --skill frontend-performance-optimization
Clone the repo
git clone --depth 1 https://github.com/ProgrammerAnthony/Expert-Coding-Harness

Made for: Claude Code, Codex, Cursor.

Per session 79 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,634 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00079 $0.01634
Opus 5 $0.00039 $0.00817
Sonnet 5 $0.00016 $0.00327
Haiku 4.5 $0.00008 $0.00163

Measured 2d ago against content hash 61daf16601b6, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

frontend-performance-optimization scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/skills/frontend-performance-optimization/SKILL.md · 145 lines

How it starts

The opening of the file, as written. The whole thing — 145 lines — stays where its author put it; the contents beside it link to each section on GitHub.

前端性能优化专家

铁律:先量化分析性能瓶颈,再给出针对性优化方案,禁止无依据的盲目优化。所有优化建议必须标注收益和成本,让用户可以按需选择。

模式识别

启动时识别用户场景:

你的需求是:
1. 性能问题排查 — 页面加载慢/卡顿,需要定位瓶颈
2. 性能指标优化 — 提升LCP/FID/CLS等核心Web Vital指标
3. 打包体积优化 — 减少构建产物大小,提升加载速度
4. 全项目性能优化 — 对整个前端项目进行系统性性能优化

工作流

阶段一:性能诊断

优先要求用户提供性能数据,或指导用户采集数据:

需要你提供以下信息以便精准定位问题:
1. 页面性能报告(Lighthouse报告、Chrome Performance面板截图)
2. 核心Web Vital指标数据(LCP、FID、CLS、FCP、TTI)
3. 打包产物分析报告(webpack-bundle-analyzer、rollup-visualizer输出)
4. 网络请求情况(瀑布图、接口响应时间、资源大小)

如果没有数据,先指导用户采集:

  • 使用Lighthouse运行全页面性能分析
  • 使用Chrome DevTools Performance面板录制页面加载/交互过程
  • 使用打包分析工具生成体积分析报告

阶段二:瓶颈定位

根据数据分析,按优先级定位瓶颈:

  1. 资源加载瓶颈:大资源未压缩、未缓存、请求数量过多
  2. 渲染瓶颈:JS执行时间过长、重渲染过多、重绘回流频繁
  3. 运行时瓶颈:长任务阻塞主线程、内存泄漏、大列表渲染卡顿

优化方案体系(按收益从高到低排序)

一、加载性能优化

1. 资源体积优化
  • JS/CSS压缩、混淆、Tree Shaking移除无用代码
  • 代码分割(路由懒加载、组件懒加载)
  • 第三方依赖优化(替换大体积库、按需引入、CDN引入)
  • 图片优化(格式转换为webp/avif、压缩、响应式图片、懒加载)
  • 字体优化(字体子集化、预加载、系统字体 fallback)
2. 资源加载策略优化
  • 关键资源预加载(preload)、非关键资源预获取(prefetch)
  • 静态资源CDN加速、合理设置缓存策略(Cache-Control)
  • 减少HTTP请求数(合并小资源、雪碧图、内联小资源)
  • 启用HTTP/2或HTTP/3提升并行加载能力
  • 按需加载非首屏资源(组件、路由、图片懒加载)
3. 首屏性能优化
  • 服务端渲染(SSR/SSG/ISR)提升首屏渲染速度
  • 骨架屏、Loading状态提升感知性能
  • 内联首屏关键CSS,避免阻塞渲染
  • 延迟加载非首屏JS/CSS资源
  • 优化关键路径,减少首屏需要加载的资源数量

二、运行时性能优化

1. JS执行优化
  • 避免长任务,大计算任务使用Web Worker离线处理
  • 防抖节流优化高频事件(scroll、resize、input、mousemove)
  • 优化React/Vue重渲染:减少不必要的组件更新、合理使用useMemo/useCallback
  • 避免同步阻塞操作,使用异步API处理大计算量任务
2. 渲染性能优化
  • 减少重绘回流:批量修改DOM、使用CSS transform/opacity做动画
  • 大列表使用虚拟滚动,只渲染可视区域内容
  • 合理使用will-change提示浏览器提前优化
  • 避免在滚动/动画事件中做复杂计算
3. 内存优化
  • 避免内存泄漏:及时清理定时器、事件监听、全局引用
  • 避免闭包滥用导致的内存无法释放
  • 大对象及时销毁,避免长时间持有引用
  • 合理使用缓存,避免缓存无限增长

三、核心Web Vital指标专项优化

LCP(最大内容绘制)优化
  • 提前加载LCP资源
  • 优化LCP资源的体积和加载优先级
  • 减少服务器响应时间(TTFB)
  • 避免LCP资源被其他资源阻塞
FID(首次输入延迟)优化
  • 减少主线程阻塞时间,拆分长任务
  • 延迟执行非关键JS代码
  • 预加载关键路径资源,减少输入时的JS执行
CLS(累积布局偏移)优化
  • 为图片/视频/iframe设置固定宽高比
  • 避免动态插入内容到现有内容上方
  • 优先使用transform做动画,避免触发布局变化
  • 提前为动态内容预留空间

输出规范

### 📊 性能瓶颈诊断
- 核心问题:[主要性能瓶颈点]
- 影响指标:[受影响的性能指标]
- 当前表现:[当前指标数值,目标数值]

### 🚀 优化方案(按优先级排序)
#### 高收益低成本(优先实施)
- [优化项]:[具体做法]
- 预期收益:[指标提升幅度,如LCP从3.2s降到1.5s]
- 实施成本:[低/中/高,改动范围描述]

#### 中收益中成本(次优先实施)
- [优化项]:[具体做法]
- 预期收益:[指标提升幅度]
- 实施成本:[低/中/高,改动范围描述]

#### 低收益高成本(可选实施)
- [优化项]:[具体做法]
- 预期收益:[指标提升幅度]
- 实施成本:[低/中/高,改动范围描述]

### ✅ 验证方法
- 优化后使用[工具名称]重新检测,对比指标变化
- 核心指标达标要求:LCP < 2.5s,FID < 100ms,CLS < 0.1

Read the full file on GitHub · 145 lines

Files

What ships with it

5 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 145 lines · 79 tokens per session scan A 61daf16601b6

Subscribe to this mod's changes

frontend-performance-optimization is a skill published in the GitHub repository ProgrammerAnthony/Expert-Coding-Harness (234 stars, last pushed 3mo ago), licensed MIT. It adds 79 tokens to every session and 1,634 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes.

obra/superpowers · 21 tokens

next-cache-components-adoption

Turn on Cache Components in a Next.js app and resolve the blocking routes it surfaces. Use when the user wants to enable, adopt, or migrate to Cache Components, flip the cacheComponents flag, work through a flood of blocking-prerender / instant validation errors, run the cache-components-instant-false codemod, or…

vercel/next.js · 95 tokens

babysit-pr

Babysit a GitHub pull request after creation by continuously polling review comments, CI checks/workflow runs, and mergeability state until the PR is merged/closed or user help is required. Diagnose failures, retry likely flaky failures up to 3 times, auto-fix/push branch-related issues when appropriate, and keep…

openai/codex · 114 tokens

imagegen

Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output…

openai/codex · 113 tokens

cpu-profile-analysis

Analyze V8/Chrome CPU profiles (.cpuprofile) and DevTools trace files (Trace-.json). Use when: profiling performance, investigating slow functions, comparing code paths, finding bottlenecks, analyzing timeToRequest, understanding call trees from sampling profiler data, analyzing layout/paint/rendering, investigating…

microsoft/vscode · 71 tokens

next-cache-components-optimizer

Drive a Next.js route to instant navigation by setting up an agentic loop, under Cache Components / PPR, on initial load (hard navigation) and client-side navigation (soft navigation). Encode the goal as a failing @next/playwright instant() e2e and work it to green, one verified route at a time; the shipped test then…

vercel/next.js · 170 tokens