Qualitycs: Optimize your website's performances
  • Home
  • Blog
  • Correct “Enable text compression” error in Lighthouse & Qualitycs

Correct “Enable text compression” error in Lighthouse & Qualitycs

Transferring data on the web costs time and money, thus it’s important to reduce those data.

One easy way to reduce the transferred data is to compress it. The easiest content to compress is the text (HTML, CSS, JavaScript,…).

If you use Qualitycs (or Lighthouse), you can see the error on this form:

As you can see in the screenshot above, enabling text compression can help increase the load time a lot!

Today, nearly all browsers support text compression. Yet, the server must be configured to send compressed files. This article describes how to enable compression on Nginx and Apache 2.

Nginx

On Nginx, you need to change only one character to enable text compression.

Open your nginx config file (usually in /etc/nginx/nginx.conf ):

1
sudo nano /etc/nginx/nginx.conf

In this file, try to find the Gzip section:

1
2
3
4
5
6
7
8
9
10
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

Lines starting with # are comments (remove the # to enable the line). In the default configuration, compression is enabled but not for many file types.

To enable gzip for more file types, including CSS and Javascript, simply uncomment the line defining the gzip_types configuration.

The same block should be:

1
2
3
4
5
6
7
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

Now that you corrected the config file, you can save it and restart nginx:

1
sudo service nginx restart

Apache 2

To enable text compression on Apache, you need the module deflate:

1
sudo a2enmode deflate

You can now restart apache to load the newly enabled module:

1
sudo service httpd restart

Result

Now that compression is enabled on your server, you should see an improvement of your Qualitycs score. For example, I gained 18 points with only that configuration change:


Want to track your website’s performance over time and optimize it efficiently? Qualitycs is a SaaS tool that runs Lighthouse regularly. You can register on https://qualitycs.dev

Want to try ?

Create an account on Qualitycs and start optimizing now. In SEO, time counts !

We will never share your email address and will never spam you.

Other interesting posts