Skip to content

Instantly share code, notes, and snippets.

@MisterWP
Created April 28, 2023 08:09
Show Gist options
  • Select an option

  • Save MisterWP/b8481f459f12eb69aa343862edd7355a to your computer and use it in GitHub Desktop.

Select an option

Save MisterWP/b8481f459f12eb69aa343862edd7355a to your computer and use it in GitHub Desktop.
Adding "Expires Headers" manually
# Ajout "Expires Headers" via htaccess
<IfModule mod_expires.c>
# Ajout des "content-type" corrects pour les fonts
AddType font/ttf .ttf
AddType font/otf .otf
AddType font/woff .woff
AddType font/woff2 .woff2
AddType image/svg+xml .svg
# Compression des fonts compatibles deflate
AddOutputFilterByType DEFLATE font/ttf font/otf image/svg+xml
# Ajout des "Expires headers" très loin dans le temps (1 an)
ExpiresActive On
# Images
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
# Video
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/mpeg "access plus 1 year"
# CSS, JavaScript
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
# Fonts
ExpiresByType font/ttf "access plus 1 year"
ExpiresByType font/otf "access plus 1 year"
ExpiresByType font/woff "access plus 1 year"
ExpiresByType font/woff2 "access plus 1 year"
# Autres
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
</IfModule>
# Ajout des "Cache-Control Headers" via htaccess
<IfModule mod_expires.c>
<IfModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|webp|swf)$">
Header append Cache-Control "public"
</filesMatch>
<filesMatch "\.(woff|woff2|ttf|svg)$">
Header append Cache-Control "public"
</filesMatch>
<filesMatch "\.(css)$">
Header append Cache-Control "public"
</filesMatch>
<filesMatch "\.(js)$">
Header append Cache-Control "private"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header append Cache-Control "private, must-revalidate"
</filesMatch>
</IfModule>
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment