Google's Core Web Vitals remain the three metrics that determine whether your site feels fast to real users: Largest Contentful Paint (LCP), Interaction to Next Paint (INP), and Cumulative Layout Shift (CLS). If you're stuck with yellow or red scores in PageSpeed Insights, the fix usually lives on the server or CDN layer—not in your theme's CSS.
I've walked dozens of clients through the same six optimizations below, and the pattern holds: tuning compression, headers, image delivery, and script execution moves scores from red to green faster than rewriting JavaScript. The steps here assume you control either Apache/nginx config, a CDN dashboard, or at minimum your cPanel .htaccess file.
1. Enable Brotli compression (or at least gzip level 6)
Text assets—HTML, CSS, JavaScript—are the easiest wins.
Brotli compresses about 15-20% better than gzip at equivalent effort, and every modern browser accepts it. If your server or CDN supports Brotli, enable it for text/* and application/javascript MIME types. Most CDNs (Cloudflare, Fastly, BunnyCDN) serve Brotli by default if the origin permits it.
Apache example
<IfModule mod_brotli.c>
AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/css
AddOutputFilterByType BROTLI_COMPRESS application/javascript application/json
AddOutputFilterByType BROTLI_COMPRESS image/svg+xml
</IfModule>
If mod_brotli isn't available, stick with gzip but raise the compression level to 6. Level 9 offers diminishing returns and burns CPU.
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|webp|avif)$ no-gzip
DeflateCompressionLevel 6
</IfModule>
For nginx, add or check your gzip_comp_level directive:
gzip on;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml;
Smaller payloads mean faster LCP, especially on mobile networks.
2. Set correct cache headers for static assets
Browsers won't cache anything unless you tell them to. The right Cache-Control header keeps repeat visitors in the green without hitting your server again.
For versioned assets—any file with a hash or version number in the name—set Cache-Control: public, max-age=31536000, immutable. That's one year, and the immutable directive tells the browser never to revalidate.
<FilesMatch "\.(js|css|woff2|jpg|jpeg|png|webp|avif|svg|ico)$">
Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>
For unversioned assets (your main stylesheet without a hash), use max-age=86400 (one day) so updates propagate quickly but returning users still skip the download.
HTML itself should carry Cache-Control: no-cache or max-age=0, must-revalidate to ensure fresh content while still allowing conditional requests with ETag.
Cloudflare caveat
Cloudflare ignores origin Cache-Control headers by default and substitutes its own rules. Check your Caching → Configuration settings and either use Page Rules to extend cache TTL or enable Respect Existing Headers if you prefer origin control.
3. Serve images in WebP or AVIF with proper sizing
Image bytes are the biggest LCP bottleneck I see in tickets.
WebP is universally supported now; AVIF offers another 20-30% size reduction but encoding is slower and support is slightly behind. Pick one format, generate responsive sizes, and serve them through <picture> or srcset.
Generate WebP versions on the fly
If you're on cPanel with ImageMagick or libwebp installed:
for img in *.jpg; do
cwebp -q 85 "$img" -o "${img%.jpg}.webp"
done
WordPress users should install a plugin that auto-converts uploads (ShortPixel, Imagify, or EWWW Image Optimizer all work). The key is delivering the WebP variant to supporting browsers without breaking fallback for older clients.
Example picture element
<picture>
<source srcset="hero-800.webp 800w, hero-1600.webp 1600w" type="image/webp">
<img src="hero-800.jpg" srcset="hero-1600.jpg 1600w" alt="Hero image" width="800" height="450">
</picture>
Always include width and height attributes. They reserve layout space and prevent CLS when the image loads.
For CDN users, most modern CDNs (Cloudflare, Bunny, ImageKit) offer automatic format conversion via query parameters or headers. Enable it and test with Accept: image/webp in your request.
4. Preload critical resources and defer non-critical scripts
LCP depends on the browser fetching your hero image or web font early. By default, the browser finds these resources only after parsing HTML and CSS, wasting hundreds of milliseconds.
Add a <link rel="preload"> in the <head> for your largest above-the-fold image and any critical fonts:
<link rel="preload" as="image" href="/images/hero.webp" type="image/webp">
<link rel="preload" as="font" href="/fonts/inter-var.woff2" type="font/woff2" crossorigin>
Preload exactly the resources the browser needs to paint the viewport. Preloading ten things defeats the purpose and can actually slow down LCP by crowding the network queue.
Defer everything else
Scripts that don't affect the initial render—analytics, chat widgets, A/B testing—should load with defer or async. Better yet, delay them until user interaction.
<script src="analytics.js" defer></script>
For third-party tags, consider a consent manager that holds scripts until the user clicks. The INP improvement is dramatic because the main thread stays free.
WordPress sites often load twenty scripts in the header. Use a plugin like WP Rocket or Asset CleanUp to defer non-critical scripts or move them to the footer.
5. Optimize your CDN and enable HTTP/3
If you're using a CDN, make sure it's actually working.
Check your Time to First Byte (TTFB) in Chrome DevTools or WebPageTest. If TTFB is over 600ms, either your origin is slow or the CDN isn't caching. Set up a cache-everything page rule for static HTML if your CMS allows it, or at minimum confirm that CSS, JS, and images return CF-Cache-Status: HIT or the equivalent header for your CDN.
HTTP/3 (QUIC) reduces connection latency, especially on mobile networks with packet loss. Cloudflare, Fastly, and BunnyCDN support it by default. If you run your own nginx instance, compile with the --with-http_v3_module flag and enable QUIC listeners:
listen 443 quic reuseport;
listen 443 ssl;
ssl_early_data on;
add_header Alt-Svc 'h3=":443"; ma=86400';
The Alt-Svc header tells the browser to try HTTP/3 on the next visit.
Regional latency
If your audience is global, check that your CDN has POPs near your users. A single-region CDN might cache everything perfectly but still deliver 300ms TTFB to visitors on another continent. Multi-region CDNs are cheap now; switching is worth it if TTFB is the blocker.
6. Inline critical CSS and remove render-blocking stylesheets
External stylesheets block rendering until downloaded and parsed. The fix is to inline the CSS needed for above-the-fold content directly into the HTML <head>, then load the full stylesheet asynchronously.
Extract critical CSS
Use a tool like Critical, Penthouse, or the built-in generator in your build pipeline to extract above-the-fold styles:
npx critical index.html --base . --inline --minify > index-critical.html
Then load the full stylesheet with media="print" and switch it back with JavaScript:
<link rel="stylesheet" href="styles.css" media="print" onload="this.media='all'; this.onload=null;">
<noscript><link rel="stylesheet" href="styles.css"></noscript>
This pattern gives you a fast first paint without waiting for the full CSS bundle.
For WordPress, plugins like WP Rocket or Autoptimize can generate and inline critical CSS automatically. Test carefully—incorrect extraction can cause flash-of-unstyled-content (FOUC) or break layout.
What about CLS?
Cumulative Layout Shift stems from missing dimensions on images, web fonts swapping, or ads pushing content down.
Fix images first: add width and height to every <img> and <picture>. Modern browsers use aspect ratio from those attributes to reserve space even if the image hasn't loaded.
For fonts, use font-display: swap in your @font-face declaration and preload the font file. Swap causes a brief flash of fallback text but prevents invisible text and layout jumps.
@font-face {
font-family: 'Inter';
src: url('/fonts/inter-var.woff2') format('woff2');
font-display: swap;
}
If ads or dynamic content cause shifts, reserve space with min-height on the container. Better yet, lazy-load ads below the fold so they never affect CLS.
Start with compression and headers
If you tackle only two items from this list, make them compression and cache headers. They're fast to implement, low-risk, and push every metric toward green without touching your theme or JavaScript. The other four—image formats, preload, CDN tuning, and critical CSS—compound the gains and get you across the finish line when those first two aren't enough.
Retest in PageSpeed Insights after each change so you know what moved the needle. Field data in Search Console takes a month to reflect improvements, so focus on lab scores first and confirm with field data later.
