AgentSkillsCN

performance-check

前端性能审计:分析Bundle大小、Core Web Vitals目标、懒加载、图像优化、缓存策略、代码分割,以及阻塞渲染资源的检测。

SKILL.md
--- frontmatter
name: performance-check
description: |
  Frontend performance audit: bundle size analysis, Core Web Vitals targets,
  lazy loading, image optimization, caching strategy, code splitting, and
  render-blocking resource detection.

Performance Check Skill

Analyze frontend projects for performance issues using static analysis. Focuses on Core Web Vitals targets, bundle efficiency, and loading strategy.

Arguments

  • $ARGUMENTS -- File or directory to audit (default: current working directory).

Phase 1: Project Detection

Identify the frontend framework and build system:

FrameworkIndicators
Next.jsnext.config.*, .next/
Vitevite.config.*
Webpackwebpack.config.*
Create React Appreact-scripts in package.json
Plain HTML*.html without framework indicators

Phase 2: Core Web Vitals Static Analysis

Check for patterns that impact each vital metric.

LCP (Largest Contentful Paint) -- Target: < 2.5s

CheckPatternSeverity
Hero image priority<img> in first viewport without fetchpriority="high"High
Preload hintsNo <link rel="preload"> for LCP resourceMedium
Server-side renderingCheck for SSR/SSG configurationMedium
Font preloadingWeb fonts without <link rel="preload" as="font">Medium
Lazy hero imageHero/above-fold <img> with loading="lazy"High

FID / INP (Interaction to Next Paint) -- Target: < 100ms / < 200ms

CheckPatternSeverity
Sync scripts in head<script> without defer or async in <head>High
Long tasksdocument.addEventListener with heavy computationMedium
Main thread blockingLarge synchronous imports in entry filesMedium
Event handler complexityComplex inline handlers (onClick with awaits)Low

CLS (Cumulative Layout Shift) -- Target: < 0.1

CheckPatternSeverity
Image dimensions<img> without width and heightHigh
Dynamic contentInjected content above fold without reserved spaceMedium
Font displayMissing font-display: swap or optionalMedium
Ad/embed slotsIframes without explicit dimensionsMedium
Aspect ratioNo aspect-ratio CSS for media containersLow

Phase 3: Bundle Analysis

If build output or config is available, analyze bundle efficiency.

CheckWhatSeverity
Bundle sizeMain bundle > 250KB (gzipped)High
Chunk countSingle monolithic bundle (no code splitting)Medium
Tree shakingImporting entire libraries (import _ from 'lodash')High
Duplicate depsSame package at multiple versions in lock fileMedium
Dynamic importsNo import() or React.lazy usage for routesMedium
CSS bundleCSS > 100KB without splitting/purgingMedium

Common Tree-Shaking Violations

PatternBetter Alternative
import _ from 'lodash'import debounce from 'lodash/debounce'
import * as Icons from '@heroicons/react'import { ArrowIcon } from '@heroicons/react/24/solid'
import moment from 'moment'import { format } from 'date-fns'

Phase 4: Loading Strategy

CheckPatternSeverity
Lazy loadingBelow-fold images without loading="lazy"Medium
Route splittingAll routes in single bundleHigh
PrefetchingNo <link rel="prefetch"> for likely next pagesLow
Service workerNo SW registration for caching (PWA)Low
CompressionNo gzip/brotli config in server or buildMedium

Phase 5: Image Optimization

CheckPatternSeverity
Modern formatsUsing .png/.jpg instead of .webp/.avifMedium
Responsive imagesNo srcset or <picture> for different viewportsMedium
Oversized imagesImage files > 500KB in sourceHigh
SVG optimizationSVG files without minification (> 10KB with whitespace)Low
Sprite usageMany small icon files instead of sprite sheet or icon fontLow

Phase 6: Caching Strategy

CheckPatternSeverity
Cache headersStatic assets without Cache-Control hints in configMedium
Content hashingOutput filenames without hash (e.g., bundle.js vs bundle.a1b2c3.js)High
Immutable assetsHashed files without immutable cache directiveLow
API cachingNo SWR/React Query/TanStack Query for data fetchingLow

Output Format

markdown
## Performance Check Report

**Target**: {path}
**Framework**: {detected-framework}
**Timestamp**: {ISO-8601}

### Core Web Vitals Risk

| Metric | Target | Risk Level | Key Issues |
|--------|--------|------------|------------|
| LCP | < 2.5s | Medium | Hero image not preloaded |
| FID/INP | < 200ms | Low | Scripts properly deferred |
| CLS | < 0.1 | High | 5 images missing dimensions |

### Bundle Analysis

| Metric | Value | Status |
|--------|-------|--------|
| Main bundle (est.) | ~180KB gz | pass |
| Code splitting | Yes (4 chunks) | pass |
| Tree shaking issues | 2 found | warn |

### Findings

| Severity | Category | File | Line | Issue | Impact |
|----------|----------|------|------|-------|--------|
| High | CLS | Hero.tsx | 12 | Image missing width/height | Layout shift on load |
| High | Bundle | utils.ts | 1 | `import _ from 'lodash'` | +70KB to bundle |
| Medium | LCP | index.html | 8 | No font preload | Delayed text rendering |

### Verdict

- **PASS**: No high-severity performance issues
- **WARN**: Some optimization opportunities
- **FAIL**: Critical performance issues likely impacting Core Web Vitals

Safety Checks

  • Read-only analysis -- never modify source files or build output
  • Skip node_modules/, dist/, build/, .next/ contents
  • Image size checks use file metadata only (no image processing)
  • Cap findings at 50 per category