# ----------------------------------------
# Browser Caching Rules (Enhances performance)
# - WordPress-optimized browser caching
# - Modern format support (AVIF, WebP, WOFF2)
# - Safe defaults for dynamic content
# ----------------------------------------

# Define MIME types for modern formats
<IfModule mod_mime.c>
    # Modern image formats
    AddType image/avif                     avif
    AddType image/avif-sequence            avifs
    AddType image/webp                     .webp
    AddType image/svg+xml                  .svg .svgz
    
    # Core web assets
    AddType text/css                       .css
    AddType text/javascript                .js .mjs
    AddType application/javascript         .js
    
    # Web fonts
    AddType font/ttf                       .ttf
    AddType font/otf                       .otf
    AddType font/woff                      .woff
    AddType font/woff2                     .woff2
    AddType application/vnd.ms-fontobject  .eot
</IfModule>

# Expires Headers - Detailed cache control
<IfModule mod_expires.c>
    ExpiresActive on
    
    # Set default expiration
    ExpiresDefault                              "access plus 1 month"
    
    # HTML document caching - no caching by default
    ExpiresByType text/cache-manifest           "access plus 0 seconds"
    ExpiresByType text/html                     "access plus 0 seconds"
    
    # Data and API
    ExpiresByType text/xml                      "access plus 0 seconds"
    ExpiresByType application/xml               "access plus 0 seconds"
    ExpiresByType application/json              "access plus 0 seconds"
    
    # Feed
    ExpiresByType application/rss+xml           "access plus 1 hour"
    ExpiresByType application/atom+xml          "access plus 1 hour"
    
    # Favicon
    ExpiresByType image/x-icon                  "access plus 1 week"
    
    # Media files
    ExpiresByType image/gif                     "access plus 4 months"
    ExpiresByType image/png                     "access plus 4 months"
    ExpiresByType image/jpeg                    "access plus 4 months"
    ExpiresByType image/webp                    "access plus 4 months"
    ExpiresByType video/ogg                     "access plus 4 months"
    ExpiresByType audio/ogg                     "access plus 4 months"
    ExpiresByType video/mp4                     "access plus 4 months"
    ExpiresByType video/webm                    "access plus 4 months"
    ExpiresByType image/avif                    "access plus 4 months"
    ExpiresByType image/avif-sequence           "access plus 4 months"
    
    # HTC files
    ExpiresByType text/x-component              "access plus 1 month"
    
    # Web fonts
    ExpiresByType font/ttf                      "access plus 4 months"
    ExpiresByType font/otf                      "access plus 4 months"
    ExpiresByType font/woff                     "access plus 4 months"
    ExpiresByType font/woff2                    "access plus 4 months"
    ExpiresByType image/svg+xml                 "access plus 4 months"
    ExpiresByType application/font-woff2        "access plus 4 months"
    ExpiresByType application/font-woff         "access plus 4 months"
    ExpiresByType application/x-font-woff       "access plus 4 months"
    ExpiresByType application/vnd.ms-fontobject "access plus 4 months"
    
    # CSS and JavaScript
    ExpiresByType text/css                      "access plus 1 year"
    ExpiresByType application/javascript        "access plus 1 year"
</IfModule>

# Cache-Control Headers
<IfModule mod_alias.c>
    <FilesMatch "\.(html|htm|rtf|rtx|txt|xsd|xsl|xml)$">
        <IfModule mod_headers.c>
            Header set X-Powered-By "Dragonizer"
            Header unset Pragma
            Header append Cache-Control "public"
            Header unset Last-Modified
        </IfModule>
    </FilesMatch>

    <FilesMatch "\.(css|htc|js|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$">
        <IfModule mod_headers.c>
            Header unset Pragma
            Header append Cache-Control "public"
        </IfModule>
    </FilesMatch>
</IfModule>

# Cross-Origin Headers for CDN
<IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
        # Images
        <FilesMatch "\.(avifs?|cur|gif|png|jpe?g|svgz?|ico|webp)$">
            SetEnvIf Origin ":" IS_CORS
            Header set Access-Control-Allow-Origin "*" env=IS_CORS
        </FilesMatch>
    </IfModule>
</IfModule>

# Web Fonts Access
<FilesMatch "\.(eot|otf|tt[cf]|woff2?)$">
    <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
    </IfModule>
</FilesMatch>