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 compress a website in cPanel.
It’s the Gzip method that speeds up blogs and websites, 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 the Gzip function or to create it is to reduce the loading time. The HTML and CSS code includes many white spaces and not optimized lines, which makes a web page load 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.
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 nowadays, but a way to succeed.
The other big benefit of using Gzip and compressing 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 limited bandwidth, 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 log in to your cPanel and find the icon ”Optimize Website”, under the Software/Services section, as the next screenshot.
The next step is to 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.
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 an NGINX 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 the 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 an outdated PHP 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.