Improve Performance with .htaccess Caching and Compression

and user-visible behaviorOriginal…

If your WordPress site feels slow, .htaccess is one of the fastest places to gain real performance improvements without changing themes or plugins. This guide focuses on practical Apache optimizations you can test safely.

What .htaccess can improve

  • Browser caching for static assets
  • Response compression (Gzip/Brotli)
  • Reduced redirect overhead
  • Fewer unnecessary file requests

1) Enable browser caching for static files

Caching CSS, JS, and images reduces repeat load times for returning visitors.

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/css "access plus 7 days"
  ExpiresByType application/javascript "access plus 7 days"
  ExpiresByType image/jpeg "access plus 30 days"
  ExpiresByType image/png "access plus 30 days"
  ExpiresByType image/webp "access plus 30 days"
  ExpiresByType image/svg+xml "access plus 30 days"
  ExpiresDefault "access plus 1 day"
</IfModule>

2) Enable compression for text assets

Compression cuts payload size and helps Core Web Vitals.

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/javascript application/json application/xml
</IfModule>

3) Remove query-string cache blockers where possible

If your stack still appends version query strings aggressively, consider filename versioning in your build/cache layer. This is often more CDN-friendly than query-only versioning.

4) Minimize redirect chains

  • Use one canonical host (for example, www only).
  • Use one protocol (HTTPS only).
  • Avoid duplicate rewrite rules in Apache + Cloudflare + plugin layers.

5) Validate after each change

curl -I https://www.wordpresshosting.solutions/
curl -I https://www.wordpresshosting.solutions/wp-content/themes/your-theme/style.css

Check response headers for cache-control, expires, and content-encoding.

WordPress-specific caution

Do not cache dynamic admin or logged-in pages aggressively. Keep admin and cart/account flows excluded from page-cache rules.

Applied correctly, these changes can improve repeat page speed without risky plugin churn.

Validation

Re-test key user paths and review service logs after each change.

Further reading: Core Web Vitals Overview

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *