Web Performance Optimization
Overview
Help developers optimize website and web application performance to improve user experience, SEO rankings, and conversion rates. This skill provides systematic approaches to measure, analyze, and improve loading speed, runtime performance, and Core Web Vitals metrics.
When to Use This Skill
- Use when website or app is loading slowly
- Use when optimizing for Core Web Vitals (LCP, FID, CLS)
- Use when reducing JavaScript bundle size
- Use when improving Time to Interactive (TTI)
- Use when optimizing images and assets
- Use when implementing caching strategies
- Use when debugging performance bottlenecks
- Use when preparing for performance audits
How It Works
Step 1: Measure Current Performance
I'll help you establish baseline metrics:
- Run Lighthouse audits
- Measure Core Web Vitals (LCP, FID, CLS)
- Check bundle sizes
- Analyze network waterfall
- Identify performance bottlenecks
Step 2: Identify Issues
Analyze performance problems:
- Large JavaScript bundles
- Unoptimized images
- Render-blocking resources
- Slow server response times
- Missing caching headers
- Layout shifts
- Long tasks blocking main thread
Step 3: Prioritize Optimizations
Focus on high-impact improvements:
- Critical rendering path optimization
- Code splitting and lazy loading
- Image optimization
- Caching strategies
- Third-party script optimization
Step 4: Implement Optimizations
Apply performance improvements:
- Optimize assets (images, fonts, CSS, JS)
- Implement code splitting
- Add caching headers
- Lazy load non-critical resources
- Optimize critical rendering path
Step 5: Verify Improvements
Measure impact of changes:
- Re-run Lighthouse audits
- Compare before/after metrics
- Monitor real user metrics (RUM)
- Test on different devices and networks
Examples
Example 1: Optimizing Core Web Vitals
## Performance Audit Results
### Current Metrics (Before Optimization)
- **LCP (Largest Contentful Paint):** 4.2s ❌ (should be < 2.5s)
- **FID (First Input Delay):** 180ms ❌ (should be < 100ms)
- **CLS (Cumulative Layout Shift):** 0.25 ❌ (should be < 0.1)
- **Lighthouse Score:** 62/100
### Issues Identified
1. **LCP Issue:** Hero image (2.5MB) loads slowly
2. **FID Issue:** Large JavaScript bundle (850KB) blocks main thread
3. **CLS Issue:** Images without dimensions cause layout shifts
### Optimization Plan
#### Fix LCP (Largest Contentful Paint)
**Problem:** Hero image is 2.5MB and loads slowly
**Solutions:**
\`\`\`html
<!-- Before: Unoptimized image -->
<img src="/hero.jpg" alt="Hero">
<!-- After: Optimized with modern formats -->
<picture>
<source srcset="/hero.avif" type="image/avif">
<source srcset="/hero.webp" type="image/webp">
<img
src="/hero.jpg"
alt="Hero"
width="1200"
height="600"
loading="eager"
fetchpriority="high"
>
</picture>
\`\`\`
**Additional optimizations:**
- Compress image to < 200KB
- Use CDN for faster delivery
- Preload hero image: `<link rel="preload" as="image" href="/hero.avif">`
#### Fix FID (First Input Delay)
**Problem:** 850KB JavaScript bundle blocks main thread
**Solutions:**
1. **Code Splitting:**
\`\`\`javascript
// Before: Everything in one bundle
import { HeavyComponent } from './HeavyComponent';
import { Analytics } from './analytics';
import { ChatWidget } from './chat';
// After: Lazy load non-critical code
const HeavyComponent = lazy(() => import('./HeavyComponent'));
const ChatWidget = lazy(() => import('./chat'));
// Load analytics after page interactive
if (typeof window !== 'undefined') {
window.addEventListener('load', () => {
import('./analytics').then(({ Analytics }) => {
Analytics.init();
});
});
}
\`\`\`
2. **Remove Unused Dependencies:**
\`\`\`bash
# Analyze bundle
npx webpack-bundle-analyzer
# Remove unused packages
npm uninstall moment # Use date-fns instead (smaller)
npm install date-fns
\`\`\`
3. **Defer Non-Critical Scripts:**
\`\`\`html
<!-- Before: Blocks rendering -->
<script src="/analytics.js"></script>
<!-- After: Deferred -->
<script src="/analytics.js" defer></script>
\`\`\`
#### Fix CLS (Cumulative Layout Shift)
**Problem:** Images without dimensions cause layout shifts
**Solutions:**
\`\`\`html
<!-- Before: No dimensions -->
<img src="/product.jpg" alt="Product">
<!-- After: With dimensions -->
<img
src="/product.jpg"
alt="Product"
width="400"
height="300"
style="aspect-ratio: 4/3;"
>
\`\`\`
**For dynamic content:**
\`\`\`css
/* Reserve space for content that loads later */
.skeleton-loader {
min-height: 200px;
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
background-size: 200% 100%;
animation: loading 1.5s infinite;
}
@keyframes loading {
0% { background-position: 200% 0; }
100% { background-position: -200% 0; }
}
\`\`\`
### Results After Optimization
- **LCP:** 1.8s ✅ (improved by 57%)
- **FID:** 45ms ✅ (improved by 75%)
- **CL
1---
2name: web-performance-optimization
3description: Optimize website and web application performance including loading speed, Core Web Vitals, bundle size, caching strategies, and runtime performance
4category: Document Processing
5source: antigravity
6tags: [javascript, react, nextjs, markdown, api, ai, document, image, seo]
7url: https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/web-performance-optimization
8metadata:
9 source: https://skillmd.com/skills/sickn33/web-performance-optimization
10---
11
12
13# Web Performance Optimization
14
15## Overview
16
17Help developers optimize website and web application performance to improve user experience, SEO rankings, and conversion rates. This skill provides systematic approaches to measure, analyze, and improve loading speed, runtime performance, and Core Web Vitals metrics.
18
19## When to Use This Skill
20
21- Use when website or app is loading slowly
22- Use when optimizing for Core Web Vitals (LCP, FID, CLS)
23- Use when reducing JavaScript bundle size
24- Use when improving Time to Interactive (TTI)
25- Use when optimizing images and assets
26- Use when implementing caching strategies
27- Use when debugging performance bottlenecks
28- Use when preparing for performance audits
29
30## How It Works
31
32### Step 1: Measure Current Performance
33
34I'll help you establish baseline metrics:
35- Run Lighthouse audits
36- Measure Core Web Vitals (LCP, FID, CLS)
37- Check bundle sizes
38- Analyze network waterfall
39- Identify performance bottlenecks
40
41### Step 2: Identify Issues
42
43Analyze performance problems:
44- Large JavaScript bundles
45- Unoptimized images
46- Render-blocking resources
47- Slow server response times
48- Missing caching headers
49- Layout shifts
50- Long tasks blocking main thread
51
52### Step 3: Prioritize Optimizations
53
54Focus on high-impact improvements:
55- Critical rendering path optimization
56- Code splitting and lazy loading
57- Image optimization
58- Caching strategies
59- Third-party script optimization
60
61### Step 4: Implement Optimizations
62
63Apply performance improvements:
64- Optimize assets (images, fonts, CSS, JS)
65- Implement code splitting
66- Add caching headers
67- Lazy load non-critical resources
68- Optimize critical rendering path
69
70### Step 5: Verify Improvements
71
72Measure impact of changes:
73- Re-run Lighthouse audits
74- Compare before/after metrics
75- Monitor real user metrics (RUM)
76- Test on different devices and networks
77
78## Examples
79
80### Example 1: Optimizing Core Web Vitals
81
82```markdown
83## Performance Audit Results
84
85### Current Metrics (Before Optimization)
86- **LCP (Largest Contentful Paint):** 4.2s ❌ (should be < 2.5s)
87- **FID (First Input Delay):** 180ms ❌ (should be < 100ms)
88- **CLS (Cumulative Layout Shift):** 0.25 ❌ (should be < 0.1)
89- **Lighthouse Score:** 62/100
90
91### Issues Identified
92
931. **LCP Issue:** Hero image (2.5MB) loads slowly
942. **FID Issue:** Large JavaScript bundle (850KB) blocks main thread
953. **CLS Issue:** Images without dimensions cause layout shifts
96
97### Optimization Plan
98
99#### Fix LCP (Largest Contentful Paint)
100
101**Problem:** Hero image is 2.5MB and loads slowly
102
103**Solutions:**
104\`\`\`html
105<!-- Before: Unoptimized image -->
106<img src="/hero.jpg" alt="Hero">
107
108<!-- After: Optimized with modern formats -->
109<picture>
110 <source srcset="/hero.avif" type="image/avif">
111 <source srcset="/hero.webp" type="image/webp">
112 <img
113 src="/hero.jpg"
114 alt="Hero"
115 width="1200"
116 height="600"
117 loading="eager"
118 fetchpriority="high"
119 >
120</picture>
121\`\`\`
122
123**Additional optimizations:**
124- Compress image to < 200KB
125- Use CDN for faster delivery
126- Preload hero image: `<link rel="preload" as="image" href="/hero.avif">`
127
128#### Fix FID (First Input Delay)
129
130**Problem:** 850KB JavaScript bundle blocks main thread
131
132**Solutions:**
133
1341. **Code Splitting:**
135\`\`\`javascript
136// Before: Everything in one bundle
137import { HeavyComponent } from './HeavyComponent';
138import { Analytics } from './analytics';
139import { ChatWidget } from './chat';
140
141// After: Lazy load non-critical code
142const HeavyComponent = lazy(() => import('./HeavyComponent'));
143const ChatWidget = lazy(() => import('./chat'));
144
145// Load analytics after page interactive
146if (typeof window !== 'undefined') {
147 window.addEventListener('load', () => {
148 import('./analytics').then(({ Analytics }) => {
149 Analytics.init();
150 });
151 });
152}
153\`\`\`
154
1552. **Remove Unused Dependencies:**
156\`\`\`bash
157# Analyze bundle
158npx webpack-bundle-analyzer
159
160# Remove unused packages
161npm uninstall moment # Use date-fns instead (smaller)
162npm install date-fns
163\`\`\`
164
1653. **Defer Non-Critical Scripts:**
166\`\`\`html
167<!-- Before: Blocks rendering -->
168<script src="/analytics.js"></script>
169
170<!-- After: Deferred -->
171<script src="/analytics.js" defer></script>
172\`\`\`
173
174#### Fix CLS (Cumulative Layout Shift)
175
176**Problem:** Images without dimensions cause layout shifts
177
178**Solutions:**
179\`\`\`html
180<!-- Before: No dimensions -->
181<img src="/product.jpg" alt="Product">
182
183<!-- After: With dimensions -->
184<img
185 src="/product.jpg"
186 alt="Product"
187 width="400"
188 height="300"
189 style="aspect-ratio: 4/3;"
190>
191\`\`\`
192
193**For dynamic content:**
194\`\`\`css
195/* Reserve space for content that loads later */
196.skeleton-loader {
197 min-height: 200px;
198 background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
199 background-size: 200% 100%;
200 animation: loading 1.5s infinite;
201}
202
203@keyframes loading {
204 0% { background-position: 200% 0; }
205 100% { background-position: -200% 0; }
206}
207\`\`\`
208
209### Results After Optimization
210
211- **LCP:** 1.8s ✅ (improved by 57%)
212- **FID:** 45ms ✅ (improved by 75%)
213- **CL