', ' ExpiresActive On', ' ExpiresByType text/html "access plus ' . $html . ' seconds"', ' ExpiresByType text/css "access plus ' . $asset . ' seconds"', ' ExpiresByType text/javascript "access plus ' . $asset . ' seconds"', ' ExpiresByType application/javascript "access plus ' . $asset . ' seconds"', ' ExpiresByType application/json "access plus ' . $html . ' seconds"', ' ExpiresByType image/jpeg "access plus ' . $asset . ' seconds"', ' ExpiresByType image/png "access plus ' . $asset . ' seconds"', ' ExpiresByType image/webp "access plus ' . $asset . ' seconds"', ' ExpiresByType image/avif "access plus ' . $asset . ' seconds"', ' ExpiresByType image/gif "access plus ' . $asset . ' seconds"', ' ExpiresByType image/svg+xml "access plus ' . $asset . ' seconds"', ' ExpiresByType image/x-icon "access plus ' . $asset . ' seconds"', ' ExpiresByType font/woff2 "access plus ' . $asset . ' seconds"', ' ExpiresByType font/woff "access plus ' . $asset . ' seconds"', ' ExpiresByType font/ttf "access plus ' . $asset . ' seconds"', ' ExpiresByType font/otf "access plus ' . $asset . ' seconds"', '', '', ' ', ' Header set Cache-Control "public, max-age=' . $asset . ', immutable"', ' ', ' ', ' Header set Cache-Control "public, max-age=' . $html . '"', ' ', '', ); } /** * nginx snippet — uses `expires` directive (the canonical nginx way) * plus an `add_header` line for the immutable flag. */ public static function nginx_snippet( array $opts = array() ): string { $asset = (int) ( $opts['asset_ttl'] ?? self::DEFAULT_ASSET_TTL ); $html = (int) ( $opts['html_ttl'] ?? self::DEFAULT_HTML_TTL ); return implode( "\n", array( 'location ~* \.(css|js|jpg|jpeg|png|gif|webp|avif|svg|ico|woff2|woff|ttf|otf|eot|mp4|webm|mp3|ogg)$ {', ' expires ' . $asset . 's;', ' add_header Cache-Control "public, max-age=' . $asset . ', immutable";', '}', 'location ~* \.html$ {', ' expires ' . $html . 's;', ' add_header Cache-Control "public, max-age=' . $html . '";', '}', ) ); } }