Copress a website using Gzip

How to Compress a Website using Gzip in cPanel

In Blogging by Fathi Arfaoui2 Comments

To satisfy your visitors and get the maximum appreciation from them, you need to optimize your web pages and make a fast website. Google crawlers can easily find your content, and you’re helping yourself to get indexed easier than with a slow website. But sometimes, people forget or even neglect some easy tasks that can make their websites fast in a few seconds and best of all, it’s in your hosting account. Today I’ll show you how to how to compress website in cPanel.

It’s the Gzip method that speeds up blogs and website, and it’s not specified for WordPress or any other platform, it’s general, for any hosting account with cPanel.

Why do you need to compress your web pages?

The main reason to enable Gzip function or to create it, is to reduce the loading time. The HTML and CSS code include many white spaces and not optimized lines which make a web page loads slowly for a long time that the browser takes to download the data associated with every request. The good news is that you can reduce the downloaded data from your server by 70%  in the majority of cases.

Read also: How to speed up a WordPress website.

In the compressed case, the browser requests your pages, including, their HTML and CSS codes, and it gets them compressed. That means faster loading time for your website, this is why compressing your website is not an option in our days, but a way to succeed.

The other big benefit to use Gzip and compress your web pages is to save bandwidth. This works perfectly for people who don’t use a CDN to speed up their sites. If you have a limited and little bandwidth limitation, you will save the majority of your regular bandwidth, remember that you will reduce the data size, that will work between the server and the browser by 70%.

Now, let’s compress your website:

The first step is to login to your cPanel, and find the icon ”Optimize Website”, under Software/Services section as the screenshot below:

how to Compress a Website in Cpanel

The next step is select the option “compress all content” and save the settings. You can also, compress only any type of content you want, such as text/Html etc… But the ideal way is to compress all the content. That will never have any negative impact, but, it will reduce the time that the browser downloads the content from the server.

compress all conent in cPanel

Now your server will send compressed data to any browser. As you can see, it’s only an option included in your cPanel account that you can use.

What if You don’t have the Gzip option in cPanel?

If for any reason you don’t have cPanel as your website hosting management account, and you have the NGINX web server, you can add the below code to your htaccess file:
gzip on;
gzip_comp_level 2;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

# Disable for IE < 6 because there are some known problems
gzip_disable "MSIE [1-6].(?!.*SV1)";

# Add a vary header for downstream proxies to avoid sending cached gzipped files to IE6
gzip_vary on;
For  Apache server, you need to add the below code in the htaccess file:

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.*

Now, you will see a better page speed and loading time. If you have an old hosting server with outdated Php and version, then, you should think about a modern hosting server, to be able to compress your site files and optimize your pages for better loading time.

Fathi Arfaoui: A Physicist, Blogger, and the founder and owner of He shares Business, Blogging, WordPress, Web Safety, and Blogging tips to build better websites and blogs. Also, he shares online marketing strategies and recommendations.


  1. Firat


    Everyone has different codes for htacess. How do I know which one is the right one? Also, do I need to gzip all the css and js files and call them in html files? Or, is it enough to enable gzip on the server side? Could you please explain?

    Thank you.

    1. Author
      Fathi Arfaoui

      Hi, I don’t recommend using the htaccess if you don’t know about it, if you made a mistake once, it can cause more issues. So, just use the cPanel method and don’t worry about any CSS or Java compression. Just do that once, and it will speed up your site like never before and with no issues.

Leave a Comment