3
0 Comments

Correct “Enable text compression” error in Lighthouse

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 of this form:
Lighthouse error Enable text compression

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

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

Enable text compression for 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):

sudo nano /etc/nginx/nginx.conf

In this file, try to find the Gzip section:

##
# 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:

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:

sudo service nginx restart

Enable text compression on Apache 2

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

sudo a2enmode deflate

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

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:
Score evolution thanks to text compression


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

posted to Icon for group Developers
Developers
on May 22, 2022
Trending on Indie Hackers
30 days ago I posted here with $0 revenue. Here's what actually happened next. User Avatar 151 comments How to spot high-intent customers in 5 minutes, for free. User Avatar 48 comments Fixing broken scrapers instead of working on my actual product. So I made it my problem. User Avatar 39 comments I Built a Habit Tracker SaaS Alone in 6 Weeks (No CS Degree, No Team). Here's Exactly How User Avatar 39 comments I built an open-source PII masking layer for LLM APIs — early traction, looking for design partners User Avatar 29 comments How to see revenue problems before they get worse User Avatar 23 comments