When and why you should turn on compaction for your website.
What to do when the PageSpeed review suggests that you turn on your site's compression, see the steps required to enable this feature in WordPress or Magento.
Example message in PageSpeed
Compacting features with gzip or deflate can reduce the number of bytes sent over the network.
Enable compression for the following features to decrease the transfer size in 328,4 KiB (73% reduction).
Who should do this?
You should enable compression when the PageSpeed Insights detects that compressible passive resources have not been compressed.
All modern browsers automatically support gzip compression for all HTTP requests.
Enabling gzip compression can reduce the response size by up to 90%, which can significantly reduce the amount of time to download the feature, reduce data usage for the client, and improve the rendering time of your pages.
Recommendations to enable compression
Enable and test gzip compression support on your web server.
The HTML5 Boilerplate project contains sample configuration files for all most popular servers with detailed comments for each configuration and configuration flag: find your favorite server in the list, browse to the gzip section, and confirm that your server is configured with the recommended settings.
See your web server's documentation for how to enable compression.
Typically sites / virtual stores like Magento, WordPress, PHP platforms are running on an Apache server.
Enabling Gzip Compression via .htaccess
Configuring compression directly on the server has several benefits.
On the one hand, plugins come with a lot of indirect data, which increases the risk of conflicts with other plugins and errors.
Also, if compression is all you're looking for, installing a large plugin with dozens of other functions does not make sense.
As mentioned earlier, the server file responsible for enabling these features is called .htaccess (yes, including the dot).
It is used to implement special instructions for the server.
For example, when you set up enough permalinks in WordPress, CMS adds rewriting rules to .htaccess for this to happen.
Other things this file can do are redirects, protecting files and folders from access and more, including Gzip compression.
Here's how to do the latter.
Find and edit .Htaccess
To make changes to the file Htaccess, we must first find it. This is not always easy because it is hidden by default.
The easiest way to access .htacces is via FTP, but you can also use cPanel or any other administration interface.
In our case, let's start by opening our FTP client and connecting it to the server.
.htaccess is usually found in the root directory of your site. However, as I mentioned, it is often invisible.
In FileZilla, you can change this in Server> Force showing hidden files.
However, your access mode may have the option elsewhere.
After that, you can edit the file just like any other file. In Filezilla this means right-click and then View / Edit.
Add the required code
Add the following code at the end of the .htaccess file and save it to your server.
Now you can check if Gzip compression is working on your site.
Run the PageSpeed test again and make sure your website's note has improved.