Skip to content

Instantly share code, notes, and snippets.

@nilovelez
Created May 4, 2017 07:11
Show Gist options
  • Save nilovelez/0543c58955dd9c5e5cb028edf470b9dc to your computer and use it in GitHub Desktop.
Save nilovelez/0543c58955dd9c5e5cb028edf470b9dc to your computer and use it in GitHub Desktop.
.htaccess GZIP + browser cache
# ———————————————————————
# Force Cache
# ———————————————————————
<IfModule mod_expires.c>
<FilesMatch "\.(jpe?g|png|gif|js|css|ico)$">
ExpiresActive On
ExpiresDefault "access plus 1 year"
</FilesMatch>
</IfModule>
# ———————————————————————
# Gzip compression
# ———————————————————————
<IfModule mod_deflate.c>
#The following line is enough for .js and .css
AddOutputFilter DEFLATE js css
#The following line also enables compression by file content type, for the following list of Content-Type:s
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml
#The following lines are to avoid bugs with some browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment