Options -MultiViews
RewriteEngine On

# Serve existing files and directories directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Route everything else to index.html (SPA fallback)
RewriteRule ^ index.html [QSA,L]

# ── Cache headers ──────────────────────────────────────────────────────────
<IfModule mod_expires.c>
  ExpiresActive On

  # Hashed assets (JS/CSS) → cache 1 year
  <FilesMatch "\.(js|css|woff2|woff|ttf|eot)$">
    ExpiresDefault "access plus 1 year"
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>

  # Images → cache 30 days
  <FilesMatch "\.(png|jpg|jpeg|gif|webp|svg|ico)$">
    ExpiresDefault "access plus 30 days"
    Header set Cache-Control "public, max-age=2592000"
  </FilesMatch>

  # JSON data (blog posts) → cache 1 hour
  <FilesMatch "\.json$">
    ExpiresDefault "access plus 1 hour"
    Header set Cache-Control "public, max-age=3600"
  </FilesMatch>

  # HTML → no cache (always fresh)
  <FilesMatch "\.html$">
    ExpiresDefault "access plus 0 seconds"
    Header set Cache-Control "no-cache, no-store, must-revalidate"
  </FilesMatch>
</IfModule>

# ── GZIP compression ────────────────────────────────────────────────────────
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json
</IfModule>
