# ─────────────────────────────────────────────────────────────────────────────
# Flutter Web on Apache / cPanel — lives in web/ so every `flutter build web`
# copies it into build/web automatically. Upload build/web/* into public_html.
# ─────────────────────────────────────────────────────────────────────────────

# Compress text assets on the wire. This is the biggest load-speed win: main.dart.js
# (~4 MB) drops to ~1 MB and the CanvasKit .wasm shrinks a lot, so the first paint
# arrives far sooner. Brotli is used when the host supports it, else gzip (mod_deflate).
<IfModule mod_brotli.c>
  AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/css application/javascript application/json application/wasm image/svg+xml font/ttf
</IfModule>
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/css application/javascript application/json application/wasm image/svg+xml font/ttf
</IfModule>

# Route deep links (e.g. /products/123) back to index.html; Flutter's router
# resolves the path on the client. Real files/dirs are served directly.
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]
  RewriteRule ^ index.html [L]
</IfModule>

# Never cache the entry/bootstrap files, so new deploys appear immediately.
<IfModule mod_headers.c>
  <FilesMatch "(index\.html|flutter_bootstrap\.js|flutter_service_worker\.js)$">
    Header set Cache-Control "no-cache, no-store, must-revalidate"
  </FilesMatch>
</IfModule>

# Long-cache the hashed build assets (main.dart.js, canvaskit, fonts, wasm).
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType application/javascript "access plus 1 year"
  ExpiresByType text/css "access plus 1 year"
  ExpiresByType image/png "access plus 30 days"
  ExpiresByType image/jpeg "access plus 30 days"
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType application/wasm "access plus 1 year"
</IfModule>
