Make your CMS faster

Platform Optimised Hosting

Back to blog

How to Enable Compression

Optimising your website will not only provide a better visitor experience, it will also position you to rank well with Google, Bing, Yahoo and other search engines. One way to speed up websites is to enable gzip compression…

 

What is compression?

Compression is a way of compressing files sent from your server to increase the speed to which they are transferred to the user’s web browser.

It can reduce page sizes by up to 70% and subsequently improve load times.

 

Activating compression for Litespeed

If your server is running Litespeed Web Server – which includes all our shared, reseller and optweb servers – then Brotli compression is enabled by default.

Brotli compression is newer and slightly faster than the standard GZip compression, but not all page speed testing services can detect it yet.

You can confirm Brotli compression is active in the site’s headers by looking for “content-encoding: br” like this:

Litespeed will silently fall back to GZip on any browser that isn’t compatible with Brotli.

 

Activating compression for Apache

Depending on your Content Management System, and/or server type you will find there are various methods to enable Gzip compression…

WordPress and Gzip compression

Most popular caching plugins have the facility to enable the function via their settings. I use WP Fastest Cache and the option is available via the settings home page:

Gzip Compression

Enable compression via .htaccess

Typically when enabling Gzip via a WordPress plug-in it is done by adding content to your .htaccess file. If you do not use WordPress or prefer not to use a caching add-on, you can enable Gzip compression manually by adding the following to .htaccess:

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

Enabling compression on Apache webservers

If gzip fails using the instructions above, remove the code added to .htaccess and replace with:

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

Checking Gzip is enabled on Apache

A good tool to analyse on site performance is GTmetrix.com. A previous blog post Improve Your GTmetrix Score in Under 30 Minutes gives insight on steps you can take to improve your score. Enter your website url, click ‘Analyse’ and once the report has run you will be notified whether Gzip has been enabled successfully:

Gzip Compression


Avatar photo
Scott Pollard

Digital Creative / Developer

Scott is the creative mind behind our digital presence, combining his skills in design and development to craft seamless online experiences. With a passion for innovative web design and a knack for solving complex coding challenges, Scott ensures that our digital platforms are both visually stunning and highly functional. When he's not coding or sketching new ideas, Scott enjoys exploring the latest tech trends and refining his skills in the ever-evolving digital landscape.

@clookinternet