Skip to content

Instantly share code, notes, and snippets.

@shrinkray
Last active August 26, 2022 09:42
Show Gist options
  • Select an option

  • Save shrinkray/92923f6777bfb51bb5737cf03fe0cbc6 to your computer and use it in GitHub Desktop.

Select an option

Save shrinkray/92923f6777bfb51bb5737cf03fe0cbc6 to your computer and use it in GitHub Desktop.
HTACCESS & Apache, Improve grade on GTMetrix without the help of plugins.
# BEGIN KEEP ALIVE
<IfModule mod_headers.c>
Header set Connection keep-alive
</IfModule>
# END KEEP ALIVE
# BEGIN EXPIRES
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
# END EXPIRES
# BEGIN HEADER ETAG
Header unset ETag
FileETag None
# END HEADER ETAG
# BEGIN SVG GZIP COMPRESSION with Deflate
AddType image/svg+xml svg svgz
<IfModule mod_deflate.c>
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE "image/svg+xml" \
"text/css" \
"text/html" \
"text/javascript"
</IfModule>
</IfModule>
# END SVG GZIP COMPRESSION
# BEGIN MORE GZIP COMPRESSION with BrowserMatch
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript application/x-httpd-php
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
Header append Vary User-Agent env=!dont-vary
# END MORE GZIP COMPRESSION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment