# Flutter Web on Apache: SPA routing, caching, compression, and correct MIME types Options -MultiViews RewriteEngine On # Serve existing files/directories directly RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] # Fallback all other requests to index.html (client-side routing) RewriteRule ^ index.html [L] # Correct MIME types (important for CanvasKit/WebAssembly and fonts) AddType application/wasm wasm AddType font/woff2 woff2 AddType application/javascript js AddType text/css css # Caching policy # Long cache for static assets (Flutter uses hashed filenames) Header set Cache-Control "public, max-age=31536000, immutable" # Service configs/JSON can be cached briefly Header set Cache-Control "public, max-age=3600" # Never cache service worker or manifest (avoid stale app shell) Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0" Header set Cache-Control "no-cache, max-age=0" # Never cache the HTML entry point Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0" # Minimal hardening Header always set X-Content-Type-Options "nosniff" Header always set Referrer-Policy "strict-origin-when-cross-origin" # Compression (enable if modules are available) AddOutputFilterByType BROTLI_COMPRESS \ text/html text/plain text/css application/javascript application/json application/wasm image/svg+xml AddOutputFilterByType DEFLATE \ text/html text/plain text/css application/javascript application/json application/wasm image/svg+xml