<IfModule mod_expires.c>
  ExpiresActive On

  # CSS & JS: cache for a short period
  ExpiresByType text/css "access plus 10 minutes"
  ExpiresByType application/javascript "access plus 10 minutes"
  ExpiresByType application/x-javascript "access plus 10 minutes"
  ExpiresByType text/javascript "access plus 1 month"

  # Images: cache for 1 year
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/avif "access plus 1 year"

  # Videos: cache for 1 year
  ExpiresByType video/mp4 "access plus 1 year"
  ExpiresByType video/webm "access plus 1 year"
  ExpiresByType video/ogg "access plus 1 year"

  # JSON & XML: cache for 1 day
  ExpiresByType application/json "access plus 1 day"
  ExpiresByType application/xml "access plus 1 day"

  # HTML: cache for a short period
  ExpiresByType text/html "access plus 10 minutes"

  # Fonts: cache for 1 year
  ExpiresByType font/woff "access plus 1 year"
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType application/font-woff "access plus 1 year"
  ExpiresByType application/x-font-ttf "access plus 1 year"
  ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
  
  # Default fallback
  ExpiresDefault "access plus 2 days"
</IfModule>

# Optionally, add Cache-Control headers for further control.
<IfModule mod_headers.c>
    # For images
    <FilesMatch "\.(jpg|jpeg|png|gif|svg)$">
        Header set Cache-Control "public, max-age=31536000"
    </FilesMatch>
    
    # For CSS and JavaScript
    <FilesMatch "\.(css|js)$">
        Header set Cache-Control "public, max-age=2592000"
    </FilesMatch>
    
    # For fonts
    <FilesMatch "\.(woff|woff2|ttf|otf|eot)$">
        Header set Cache-Control "public, max-age=31536000"
    </FilesMatch>
</IfModule>

<IfModule mod_deflate.c>
  # Compress common text-based formats
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json application/xml

  # Compress fonts
  AddOutputFilterByType DEFLATE application/font-woff application/font-woff2 application/x-font-ttf application/vnd.ms-fontobject

  # Compress SVG and images where applicable
  AddOutputFilterByType DEFLATE image/svg+xml image/webp image/avif
</IfModule>
