SysAdmin

How to enable gzip compression on my website

JJ
Jobin Joseph · Founder and CEO
·Published 28 June 2014·1 min read

Issue

Environment

Solution

Add the following content to your .htaccess File.

# Gzip Start
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
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
</FilesMatch>
# Gzip End

Now go to gtmetrix.com and test your site. You should see 100% gzip compression.

Jobin Joseph
Jobin Joseph, Founder and CEO
5x AWS Certified, ISO 27001:2022 Lead Implementer, 17+ years building cloud infrastructure for regulated industries.
About Jobin →

Reading this because your AWS bill or uptime is a problem?

30 minutes, direct with the founder, no sales pitch: one specific recommendation for your AWS workload.

Book a free 30-minute review
30 min Free Consultation →