Web Performance Optimization: Core Web Vitals Guide 2025
Master Core Web Vitals optimization techniques for better user experience, SEO rankings, and website performance.

Emre Tekir
Frontend Developer & SDK
Web Performance Optimization: Core Web Vitals in 2025
Web performance has never been more critical. With Google's Page Experience update and the focus on Core Web Vitals, optimizing your website's performance directly impacts SEO rankings and user experience.
Understanding Core Web Vitals
Core Web Vitals are three specific factors that Google considers crucial for user experience:
1. Largest Contentful Paint (LCP)
Measures loading performance. Good LCP scores are 2.5 seconds or faster.
// Measure LCP
new PerformanceObserver((entryList) => {
const entries = entryList.getEntries();
const lastEntry = entries[entries.length - 1];
console.log('LCP:', lastEntry.startTime);
}).observe({ entryTypes: ['largest-contentful-paint'] });
2. First Input Delay (FID)
Measures interactivity. Good FID scores are less than 100 milliseconds.
// Measure FID
new PerformanceObserver((entryList) => {
const firstInput = entryList.getEntries()[0];
console.log('FID:', firstInput.processingStart - firstInput.startTime);
}).observe({ type: 'first-input', buffered: true });
3. Cumulative Layout Shift (CLS)
Measures visual stability. Good CLS scores are less than 0.1.
// Measure CLS
let clsValue = 0;
let clsEntries = [];
new PerformanceObserver((entryList) => {
for (const entry of entryList.getEntries()) {
if (!entry.hadRecentInput) {
clsValue += entry.value;
clsEntries.push(entry);
}
}
console.log('CLS:', clsValue);
}).observe({ type: 'layout-shift', buffered: true });
Advanced Performance Optimization Techniques
Image Optimization
Modern image formats and techniques:
<!-- WebP with fallback -->
<picture>
<source srcset="image.webp" type="image/webp">
<source srcset="image.avif" type="image/avif">
<img src="image.jpg" alt="Optimized image" loading="lazy">
</picture>
Critical CSS Inlining
Inline critical CSS to eliminate render-blocking:
<style>
/* Critical CSS inlined */
.hero { background: #3b82f6; height: 100vh; }
.nav { position: fixed; top: 0; width: 100%; }
</style>
<link rel="preload" href="/styles/main.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
Resource Prioritization
Use resource hints effectively:
<!-- Preload critical resources -->
<link rel="preload" href="/fonts/main.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="/api/critical-data" as="fetch" crossorigin>
<!-- Prefetch next page resources -->
<link rel="prefetch" href="/about">
<link rel="dns-prefetch" href="//external-api.com">
JavaScript Performance Optimization
Code Splitting with Dynamic Imports
Split your JavaScript bundles for better loading:
// Route-based code splitting
const HomePage = lazy(() => import('./pages/Home'));
const AboutPage = lazy(() => import('./pages/About'));
// Component-based code splitting
const HeavyComponent = lazy(() =>
import('./components/HeavyComponent')
);
Tree Shaking and Bundle Optimization
Remove unused code with modern bundlers:
// webpack.config.js
module.exports = {
mode: 'production',
optimization: {
usedExports: true,
sideEffects: false,
splitChunks: {
chunks: 'all',
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
},
},
};
Web Workers for Heavy Tasks
Offload intensive computations to Web Workers:
// main.js
const worker = new Worker('/worker.js');
worker.postMessage({ data: largeDataSet });
worker.onmessage = function(e) {
console.log('Processed data:', e.data);
};
// worker.js
self.onmessage = function(e) {
const processedData = heavyComputation(e.data);
self.postMessage(processedData);
};
Server-Side Performance
Caching Strategies
Implement multi-layer caching:
// Next.js API route with caching
export default async function handler(req, res) {
// Set cache headers
res.setHeader(
'Cache-Control',
'public, s-maxage=10, stale-while-revalidate=59'
);
const data = await fetchData();
res.json(data);
}
CDN and Edge Computing
Leverage edge networks for global performance:
// Vercel Edge Function
export const config = {
runtime: 'edge',
};
export default function handler(req) {
const country = req.geo?.country || 'US';
return new Response(`Hello from ${country}!`, {
headers: {
'cache-control': 'public, max-age=86400',
},
});
}
Monitoring and Measurement
Real User Monitoring (RUM)
Track actual user performance:
// Web Vitals measurement
import { getCLS, getFID, getFCP, getLCP, getTTFB } from 'web-vitals';
function sendToAnalytics({ name, delta, value, id }) {
// Send to your analytics service
gtag('event', name, {
event_category: 'Web Vitals',
value: Math.round(name === 'CLS' ? delta * 1000 : delta),
event_label: id,
non_interaction: true,
});
}
getCLS(sendToAnalytics);
getFID(sendToAnalytics);
getFCP(sendToAnalytics);
getLCP(sendToAnalytics);
getTTFB(sendToAnalytics);
Performance Budgets
Set and enforce performance budgets:
{
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
]
}
Framework-Specific Optimizations
Next.js Performance Features
Leverage Next.js built-in optimizations:
// next.config.js
module.exports = {
experimental: {
optimizeCss: true,
optimizeImages: true,
},
images: {
domains: ['example.com'],
formats: ['image/webp', 'image/avif'],
},
compiler: {
removeConsole: true,
},
};
React Performance Patterns
Optimize React applications:
// Memoization
const ExpensiveComponent = React.memo(({ data }) => {
return <div>{processData(data)}</div>;
});
// useMemo for expensive calculations
const processedData = useMemo(() => {
return expensiveCalculation(rawData);
}, [rawData]);
// useCallback for stable references
const handleClick = useCallback((id) => {
onItemClick(id);
}, [onItemClick]);
Mobile Performance Optimization
Responsive Images
Optimize images for different screen sizes:
<img
srcset="small.jpg 480w, medium.jpg 800w, large.jpg 1200w"
sizes="(max-width: 480px) 100vw, (max-width: 800px) 50vw, 25vw"
src="medium.jpg"
alt="Responsive image"
loading="lazy"
>
Touch and Gesture Optimization
Optimize for mobile interactions:
/* Optimize touch targets */
.button {
min-height: 44px;
min-width: 44px;
touch-action: manipulation;
}
/* Reduce paint complexity */
.animated-element {
will-change: transform;
transform: translateZ(0);
}
Performance Testing Tools
Automated Testing
Integrate performance testing in CI/CD:
// Lighthouse CI configuration
module.exports = {
ci: {
collect: {
url: ['http://localhost:3000'],
numberOfRuns: 3,
},
assert: {
assertions: {
'categories:performance': ['warn', { minScore: 0.9 }],
'categories:accessibility': ['error', { minScore: 0.9 }],
},
},
},
};
Performance Profiling
Use browser DevTools effectively:
// Performance marks and measures
performance.mark('expensive-task-start');
await expensiveTask();
performance.mark('expensive-task-end');
performance.measure(
'expensive-task',
'expensive-task-start',
'expensive-task-end'
);
Advanced Optimization Strategies
Service Worker Caching
Implement intelligent caching strategies:
// sw.js
import { precacheAndRoute, cleanupOutdatedCaches } from 'workbox-precaching';
import { registerRoute } from 'workbox-routing';
import { StaleWhileRevalidate, CacheFirst } from 'workbox-strategies';
// Precache static assets
precacheAndRoute(self.__WB_MANIFEST);
cleanupOutdatedCaches();
// Cache API responses
registerRoute(
({ url }) => url.pathname.startsWith('/api/'),
new StaleWhileRevalidate({
cacheName: 'api-cache',
})
);
// Cache images
registerRoute(
({ request }) => request.destination === 'image',
new CacheFirst({
cacheName: 'images-cache',
plugins: [{
cacheKeyWillBeUsed: async ({ request }) => {
return `${request.url}?version=1`;
},
}],
})
);
HTTP/3 and QUIC
Leverage modern protocols:
# Nginx configuration for HTTP/3
listen 443 quic reuseport;
listen 443 ssl http2;
ssl_early_data on;
ssl_protocols TLSv1.3;
add_header Alt-Svc 'h3=":443"; ma=86400';
Conclusion
Web performance optimization is an ongoing process that requires attention to detail and continuous monitoring. By focusing on Core Web Vitals and implementing advanced optimization techniques, you can create web applications that not only rank well in search engines but also provide exceptional user experiences.
Remember that performance optimization is not a one-time task but a continuous process. Regular monitoring, testing, and optimization ensure your applications maintain peak performance as they grow and evolve.
Need help optimizing your website's performance? Contact AestheteSoft for expert performance optimization services.
This article is part of the AestheteSoft blog series. Follow our blog for more insights on web performance and optimization.