Karachi, Pakistan Mon–Sat: 10AM–7PM PKT
Home Services
Design & Development
UI/UX Design Web Development WordPress Development Responsive Web Design Corporate Website Landing Pages / Microsites E-Commerce Solutions Mobile App Development
Marketing & Growth
SEO Services Content Marketing Social Media Marketing PPC / Google Ads Branding & Creative Speed & Performance
Hosting & Support
Web Hosting Maintenance & Support
Portfolio
Website Design Logo & Graphics
Clients About Blog Free Tools Get a Quote
SEO & Speed Guide

How to Enable Gzip and Brotli Compression on Your Website

How HTTP compression works, how much it saves, how to check it, and how to enable Gzip and Brotli on Apache, LiteSpeed, Nginx and Cloudflare.

Enable Gzip compression: compressed website files travelling faster to a browser

Gzip and Brotli compression shrink text files such as HTML, CSS, JavaScript, JSON and SVG before the server sends them, often by 70 to 90 percent. The browser decompresses them instantly, so pages download faster, especially on mobile data. Brotli usually compresses text 15 to 25 percent smaller than Gzip and is supported by every modern browser over HTTPS. Most good hosts and CDNs enable it automatically; if yours does not, you can turn it on in .htaccess, Nginx or Cloudflare in a few minutes. This guide shows how to check, enable and test compression. This guide explains how to enable Gzip compression step by step.

Key takeaways
  • Compress text files (HTML, CSS, JS, JSON, SVG, XML, fonts like TTF). Do not re-compress JPG, PNG, WebP, MP4 or WOFF2.
  • Prefer Brotli, with Gzip as the fallback for clients that do not accept Brotli.
  • Check with curl or DevTools: the response should show content-encoding: br or gzip.
  • If you use Cloudflare, compression to visitors is handled at the edge automatically.

Enable Gzip compression: how HTTP compression works

The browser tells the server which formats it understands in a request header:

Accept-Encoding: gzip, deflate, br, zstd

Also, the server picks one, compresses the response and labels it:

Content-Encoding: br
Vary: Accept-Encoding

The Vary header tells caches and CDNs to store separate copies for clients that accept different encodings.

Enable Gzip compression: how much it saves

FileUncompressedGzipBrotli
HTML page120 KB~24 KB~20 KB
Main CSS180 KB~30 KB~25 KB
JavaScript bundle400 KB~120 KB~100 KB

Figures are typical examples; exact savings depend on the content. Text with lots of repetition, such as page-builder HTML and CSS, compresses especially well.

Enable Gzip compression: how to check if compression is on

From the command line:

curl -sI -H "Accept-Encoding: br,gzip" https://www.example.com/ | grep -i content-encoding
curl -sI -H "Accept-Encoding: br,gzip" https://www.example.com/css/style.css | grep -i content-encoding

In Chrome DevTools → Network, add the "Content-Encoding" column (right-click the column headers → Response Headers). PageSpeed Insights also flags "Enable text compression" if it is missing.

Enable Gzip compression: enable Gzip and Brotli on Apache or LiteSpeed (.htaccess)

Many shared hosts in Pakistan run LiteSpeed, which compresses automatically. On Apache, add this to .htaccess:

<IfModule mod_brotli.c>
  AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/css text/xml
  AddOutputFilterByType BROTLI_COMPRESS application/javascript application/json application/xml
  AddOutputFilterByType BROTLI_COMPRESS image/svg+xml font/ttf application/vnd.ms-fontobject
</IfModule>

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml
  AddOutputFilterByType DEFLATE application/javascript application/json application/xml
  AddOutputFilterByType DEFLATE image/svg+xml font/ttf application/vnd.ms-fontobject
</IfModule>

The IfModule wrappers make the rules safe: if a module is not installed, the block is skipped instead of causing a 500 error. If neither works, ask your host to enable mod_deflate or mod_brotli.

Enable Gzip compression: enable compression on Nginx

gzip on;
gzip_comp_level 5;
gzip_min_length 256;
gzip_vary on;
gzip_types text/plain text/css application/javascript application/json
           application/xml image/svg+xml font/ttf;

# Requires the ngx_brotli module
brotli on;
brotli_comp_level 5;
brotli_types text/plain text/css application/javascript application/json
             application/xml image/svg+xml font/ttf;

Text/html is always compressed by Nginx when gzip is on, so it does not need to be listed. Levels 4 to 6 give most of the saving without much CPU cost for on-the-fly compression.

Pre-compressing static files

For maximum Brotli compression (level 11) without slowing responses, build tools can create .br and .gz files at deploy time. Nginx then serves them with brotli_static on; and gzip_static on;. This is common for JavaScript-heavy sites built with Vite or webpack.

Compression with Cloudflare and CDNs

Cloudflare compresses responses to visitors with Brotli or Gzip automatically, regardless of what your origin server sends. Other CDNs such as BunnyCDN and the Hostinger CDN also support Brotli. See our Cloudflare setup guide and what a CDN does.

What not to compress

  • JPG, PNG, WebP, AVIF and GIF images are already compressed; optimise them instead with our image compression guide.
  • MP4 and other video files.
  • WOFF2 fonts, which already use Brotli internally.
  • ZIP and PDF downloads, which gain little.

Frequently asked questions

Is Brotli better than Gzip?

For text, yes: smaller files at similar speed for decompression. Keep Gzip enabled as a fallback.

Does compression use a lot of server CPU?

At moderate levels, very little. Caching plugins and CDNs also cache compressed copies so the work is not repeated.

Why does PageSpeed still say "Enable text compression"?

Usually a third-party script or a file type not in your list, such as JSON or SVG. Check the URLs it lists.

Related guides: Why Website Speed Matters and How to Make Your Site Faster, How to Get Your Website on Google and 301 vs 302 Redirects.

For official guidance, see web.dev by Google.

Need a faster site?

Our speed optimization service configures compression, caching and CDNs on your hosting. Contact us.

Written by the ItsWebExpert team, a web design and development company in Karachi building websites, online stores and apps for businesses across Pakistan.

Ask a Question on WhatsApp

Let's Build Your
Next Website

Tell us what you need and we will reply within 24 hours with honest advice and a fixed quote.

Trusted by our clients, rated 5.0 on Google

5.0 11 Google reviews Read all →
I had a great experience working with Waqas and his team. We got some website development and SEO work done, and I'm quite satisfied with the overall results. They understood our requirements, suggested improvements, and handled the work professionally. What I appreciated most was their communication, attention to detail, and willingness to make changes whenever needed. Waqas is very cooperative, and the team knows what they're doing. Definitely a good choice for anyone looking for reliable web development and digital marketing services.
HUHafiz Ubaid Google review · Nov 2026
I was referred to their company by someone, and I'm really glad I connected with them. Waqas, the CEO, is a very humble and professional person who leads his team exceptionally well. Their expertise in digital marketing, web development, and custom development services is impressive. The team is skilled, responsive, and committed to delivering quality work. Had a really positive experience working with them. Highly recommended!
MRMuhammad Rafeeq Google review · Nov 2026
I had hired them for my client's task of Custom Wordpress plugin development. and many other tasks later on.. Waqas is super fast and sharp.. I know him since 2019.. I really really appreciate his work. Highly recommended..
RFRaheela Farooqui Google review · Nov 2026
I had a positive experience working with Waqas and his team. They provided excellent support with graphic design and social media management. The team was professional, responsive, and attentive to our needs. They understood our vision and delivered quality work on time. Highly recommended for anyone looking for creative and reliable digital services.
URUsman Rock Google review · Nov 2026
I really appreciate their dedication and professionalism. They have a good understanding of SEO, social media marketing, and online brand growth. Communication is smooth, and the quality of work is impressive. Definitely a great team to work with!
SSSameer Sarafaraz Google review · Nov 2026
I've had a great experience working with their team. They understand digital marketing very well and know how to improve online visibility through effective SEO and marketing strategies. Professional, responsive, and reliable. Highly recommended! 🙌❤️
MNMohammad naveed Google review · Nov 2026
I had a really good experience with web Experts. Everything was easy to understand, well-organized, and user-friendly. I appreciate the effort and attention to detail that has gone into creating this platform. It was a smooth and pleasant experience, and I would definitely recommend it to others. Keep up the great work!
SSShazia shaikh Google review · Nov 2026
Extremely professional and committed I am Extremely happy to work with them I wish them best of luck Best Regards M. Salman Farooqui
SFSalman Farooqui Google review · Nov 2026
Outstanding experience! Quality, professionalism, and customer service are all excellent. Keep up the great work!
ARabdul rehman Google review · Nov 2026
Excellent service and a great experience. The team is professional, helpful, and dedicated. Highly recommended!
MEmustafa emb Google review · Nov 2026