# Vedic Visions Birth Chart Calculator
# Upload this file into the same folder as index.html.
#
# Tested against LiteSpeed (Hostinger shared hosting), which reads .htaccess
# using Apache-compatible syntax.

# ---------------------------------------------------------------------------
# 1. WebAssembly MIME type  --  REQUIRED
# ---------------------------------------------------------------------------
# Without this the server sends the .wasm file as application/octet-stream,
# the browser refuses to compile it, and the calculator never starts. The
# console error talks about "incorrect response MIME type" and does not
# mention .htaccess at all, so this is a slow one to diagnose. Do not remove.
<IfModule mod_mime.c>
  AddType application/wasm .wasm
</IfModule>

# ---------------------------------------------------------------------------
# 2. Pre-compressed data files  --  IMPORTANT
# ---------------------------------------------------------------------------
# The city and timezone datasets ship gzipped as .json.gz and are decompressed
# by the app itself. They must be served as plain files.
#
# Do NOT add "AddEncoding gzip .gz" here. That tells the browser to decompress
# them in transit, so the app then receives already-decompressed bytes. The
# loaders sniff the gzip header and cope with either case, but leaving this
# alone keeps the behaviour predictable.
<IfModule mod_mime.c>
  AddType application/gzip .gz
</IfModule>

# ---------------------------------------------------------------------------
# 3. Compression
# ---------------------------------------------------------------------------
# The .wasm file compresses from 412 KB to about 203 KB, which is the single
# biggest win available. The .json.gz files are already compressed; compressing
# them again wastes CPU and makes them slightly larger.
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css text/plain
  AddOutputFilterByType DEFLATE application/javascript application/json
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE application/wasm
</IfModule>

<IfModule mod_brotli.c>
  AddOutputFilterByType BROTLI_COMPRESS text/html text/css text/plain
  AddOutputFilterByType BROTLI_COMPRESS application/javascript application/json
  AddOutputFilterByType BROTLI_COMPRESS image/svg+xml
  AddOutputFilterByType BROTLI_COMPRESS application/wasm
</IfModule>

# ---------------------------------------------------------------------------
# 4. Caching
# ---------------------------------------------------------------------------
# Files under assets/ carry a content hash in their name, so a new build
# produces a new filename and a long cache is safe. index.html must not be
# cached hard or visitors keep loading the old build after an update.
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType application/wasm "access plus 1 year"
  ExpiresByType application/gzip "access plus 1 month"
  ExpiresDefault "access plus 1 month"
  ExpiresByType text/html "access plus 0 seconds"
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|wasm)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>
  # Datasets are regenerated only when the build is re-run, but they do not
  # carry a hash in the filename, so revalidate rather than assuming.
  <FilesMatch "\.json\.gz$">
    Header set Cache-Control "public, max-age=2592000, must-revalidate"
  </FilesMatch>
  <FilesMatch "\.html$">
    Header set Cache-Control "no-cache"
  </FilesMatch>
</IfModule>

# ---------------------------------------------------------------------------
# 5. Modest hardening
# ---------------------------------------------------------------------------
# The calculator has no forms that post anywhere, no cookies and no analytics,
# so there is little to protect, but these cost nothing.
<IfModule mod_headers.c>
  Header set X-Content-Type-Options "nosniff"
  Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

Options -Indexes
