# NRI Property Guard — performance hardening (Phase 9)
#
# This site is plain static HTML/CSS/JS with no build-time cache-busting
# (filenames don't change on redeploy), so cache lifetimes below are kept
# short enough that a future update is visible to a repeat visitor within a
# day, rather than the months-long max-age a hashed-filename site could
# safely use. If a future change needs to go out immediately to everyone,
# rename the changed file (or bump a ?v= query string in the page that
# references it) rather than only relying on these lifetimes to expire.

# ---------------------------------------------------------------
# 1. Compression — almost certainly the single biggest win on shared
#    cPanel hosting, since compression is not always on by default. Text
#    assets (HTML/CSS/JS/JSON/SVG/fonts) compress 60-80%+; already-compressed
#    binary formats (JPEG, PNG, WOFF2) are left alone since re-compressing
#    them wastes CPU for no size benefit.
# ---------------------------------------------------------------
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript
  AddOutputFilterByType DEFLATE application/javascript application/x-javascript
  AddOutputFilterByType DEFLATE application/json application/ld+json
  AddOutputFilterByType DEFLATE application/xml application/rss+xml
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE font/ttf font/otf font/eot
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject application/font-woff application/font-woff2

  # Old-IE compatibility guards some hosts still apply automatically; harmless
  # to include even though the audience here won't have IE6 in practice.
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

# ---------------------------------------------------------------
# 2. Browser caching for static assets — repeat visits (and repeat views of
#    the same portal dashboard) reuse the cached CSS/JS/font instead of
#    re-fetching it. Site JS/CSS is short-lived (1 day) since these files
#    have no cache-busting filename; fonts are effectively immutable once
#    published by Google Fonts' own CDN and are versioned there, so they can
#    safely be cached far longer. HTML pages are intentionally NOT
#    far-cached — every page here is meant to reflect the latest deploy the
#    next time someone opens it.
# ---------------------------------------------------------------
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/html "access plus 0 seconds"
  ExpiresByType text/css "access plus 1 day"
  ExpiresByType application/javascript "access plus 1 day"
  ExpiresByType text/javascript "access plus 1 day"
  ExpiresByType image/jpeg "access plus 7 days"
  ExpiresByType image/png "access plus 7 days"
  ExpiresByType image/svg+xml "access plus 7 days"
  ExpiresByType image/x-icon "access plus 7 days"
  ExpiresByType font/woff "access plus 30 days"
  ExpiresByType font/woff2 "access plus 30 days"
</IfModule>

<IfModule mod_headers.c>
  # Belt-and-braces alongside mod_expires above for hosts/proxies that only
  # honor Cache-Control. Pages themselves stay must-revalidate so a logged-in
  # dashboard is never served stale from a shared/proxy cache.
  <FilesMatch "\.(css|js)$">
    Header set Cache-Control "public, max-age=86400"
  </FilesMatch>
  <FilesMatch "\.(jpg|jpeg|png|svg|ico|webp)$">
    Header set Cache-Control "public, max-age=604800"
  </FilesMatch>
  <FilesMatch "\.(html)$">
    Header set Cache-Control "no-cache, must-revalidate"
  </FilesMatch>
</IfModule>

# ---------------------------------------------------------------
# 3. Keep-alive — lets the browser reuse one TCP/TLS connection across the
#    several CSS/JS/font requests every page makes instead of paying
#    connection-setup cost on each one. Off by default on some cPanel
#    configs.
# ---------------------------------------------------------------
<IfModule mod_headers.c>
  Header set Connection keep-alive
</IfModule>
