How to Enable Text Compression?

How to Enable Text Compression?

Free Complete Site Audit

Access a full website audit with over 300 technical insights.

Something went wrong. Please, try again later.
Trusted by
Sitechecker trusted company

Free Website SEO Checker & Audit Tool

  • Scan the site for 300+ technical issues
  • Monitor your site health 24/7
  • Track website rankings in any geo

What Does “Enable Text Compression” Mean?

“Enable text compression” refers to the process of reducing the size of text data being transferred over the internet. This is typically achieved through the use of compression algorithms that encode the text in a more efficient format, which can significantly decrease the amount of data that needs to be sent between a server and a client (e.g., a web browser). Here’s a more detailed breakdown of what it means and why it’s important:

  • Reduction in Data Size. Text compression algorithms, such as Gzip, Brotli, and Deflate, compress text files like HTML, CSS, JavaScript, and JSON. This means the same information is transmitted using fewer bytes.
  • Implementation. Enabling text compaction usually involves configuring the server to compress the files before sending them to the client. Most modern web servers and content delivery networks (CDNs) support text compaction.

Why it’s Important

Compressed text files are smaller, which means they take less time to transfer over the network. This results in faster load times for web pages and improved user experience.

Compressing text reduces the amount of data that needs to be transferred, saving bandwidth. This is especially important for users on mobile devices or with limited data plans.

Faster transfer times and reduced data sizes contribute to better overall performance of websites and web applications.

How it Works

When a client (e.g., a web browser) requests a resource from a server, it can indicate its support for compression by including an Accept-Encoding header in the request. The server then compresses the response using one of the supported compression algorithms and indicates the compression method used in the Content-Encoding header.

The client receives the compressed data and decompresses it before rendering the content. This process is usually seamless and handled automatically by the browser.

Example

1. Request. A browser requests a webpage and includes the header Accept-Encoding: gzip, deflate, br.

Response: The server responds with the compressed content and includes the header Content-Encoding: gzip.

2. Decompression. The browser decompresses the content and displays the webpage.

Enabling text compression is a best practice for web development as it enhances the speed and efficiency of data transfer, leading to a better user experience.

What Triggers This Issue?

Some or all pages don’t have a content-encoding header set to br, gzip, or deflate. Each of these file formats is used for file compression. If you use one of them, the browser can download the zipped files, extract them, and show them to users.

How to Check the Issue?

You can use several methods to check if text compression is enabled on a website. Here are some of the most common ways:

Using Online Tools

There are several online tools available that can check if text compression is enabled for your website. Some popular ones include:

GTmetrix

– Go to GTmetrix.

GTmetrix Main

– Enter your website URL and analyze it.

GTmetrix Report

– Look for the recommendations or the “Enable text compression” section to see if it’s enabled.

WebPageTest

– Visit WebPageTest.

– Enter your website URL and run the test.

WebPageTest Main

– Check the results for text compaction under the performance recommendations.

WebPageTest Summary

Using Command Line Tools

cURL

  • Open your terminal or command prompt.
  • Use the following command to check the headers:

curl -I -H "Accept-Encoding: gzip, deflate, br" https://yourwebsite.com

Look for the Content-Encoding header in the response.

wget

  • Open your terminal or command prompt.
  • Use the following command to fetch headers

wget --header="Accept-Encoding: gzip, deflate, br" -S https://yourwebsite.com
  • Check the output for the Content-Encoding header.

Using Browser Developer Tools

Google Chrome

  • Open the website you want to check.
  • Press F12 or right-click and select “Inspect” to open Developer Tools.
  • Go to the “Network” tab.
  • Reload the page.
  • Click on one of the text-based resources (e.g., HTML, CSS, JavaScript) in the list.
  • In the headers section, look for the Content-Encoding header. It should show gzip, br, or deflate if compression is enabled.

Mozilla Firefox

  • Open the website.
  • Press F12 or right-click and select “Inspect Element” to open Developer Tools.
  • Go to the “Network” tab.
  • Reload the page.
  • Click on one of the text-based resources.
  • Check the Content-Encoding header in the response headers.

How to Fix the Issue?

Fixing the issue of text compaction not being enabled involves configuring your web server or content delivery network (CDN) to compress text-based files before sending them to the client. Here’s a step-by-step guide for various common web servers:

1. Apache

To enable Gzip compression in Apache, you need to modify the .htaccess file or the server configuration file.

Using .htaccess file

  1. Open the .htaccess file in the root directory of your website.
  2. Add the following lines to enable Gzip compression:

<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
</IfModule>

Using httpd.conf or apache2.conf

  1. Open your Apache configuration file (httpd.conf or apache2.conf).
  2. Add the same lines as above inside the <IfModule mod_deflate.c> section.
  3. Restart Apache

sudo service apache2 restart

2. Nginx

To enable Gzip constriction in Nginx, you need to modify the nginx.conf file.

  1. Open the nginx.conf file.
  2. Add the following lines within the http block:

http {
gzip on;
gzip_comp_level 5;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_vary on;
}

3. Restart Nginx

1. IIS

To enable compression in Internet Information Services (IIS):

  1. Open the IIS Manager.
  2. Select your server name.
  3. In the Features View, double-click “Compression”.
  4. Check “Enable dynamic content compression” and “Enable static content compression”.
  5. Apply the changes.

2. Using a CDN

Most CDNs, such as Cloudflare, AWS CloudFront, and others, provide options to enable text compression:

Cloudflare:

  1. Log in to your Cloudflare account.
  2. Select the site.
  3. Go to the “Speed” tab.
  4. Scroll down to the “Auto Minify” section and enable “JavaScript”, “CSS”, and “HTML”.
  5. Go to the “Caching” tab.
  6. Ensure “Always Online” and “Development Mode” are turned off to use the compression features effectively.

AWS CloudFront:

  1. Open the CloudFront console.
  2. Select the distribution and click “Edit”.
  3. Scroll to the “Compress Objects Automatically” section.
  4. Check “Yes” and save changes.

3. Testing the Configuration

After making these changes, test if text compression is enabled by using browser developer tools or online tools like GTmetrix, WebPageTest, or Google PageSpeed Insights as described earlier.

Example for Nginx Configuration:

Open your Nginx configuration file:


sudo nano /etc/nginx/nginx.conf

Add or update the following lines in the http block


http {
gzip on;
gzip_comp_level 5;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_vary on;
}

Save and close the file.

Restart Nginx


sudo service nginx restart

By following these steps for your specific server or CDN, you can enable text compression and improve your website’s performance.

Final Idea

Enabling text compression reduces the size of text data transferred over the internet, enhancing website performance and user experience. This involves configuring servers or CDNs to use algorithms like Gzip, Brotli, or Deflate to compress files. This process saves bandwidth, speeds up load times, and is typically managed via server settings or CDN configurations. Users can check if compression is enabled using online tools (GTmetrix, WebPageTest) or command line tools (cURL, wget), and fix issues by modifying server settings in Apache, Nginx, IIS, or through CDN platforms like Cloudflare or AWS CloudFront.

Fast Links

You may also like

View More Posts
What if There is a Missing Viewport <meta> Tag?
Site Audit Issues
What if There is a Missing Viewport Tag?
Ivan Palii
Sep 13, 2023
The Initial Scale in the Viewport Meta Tag is Not Working
Site Audit Issues
The Initial Scale in the Viewport Meta Tag is Not Working
Ivan Palii
Sep 14, 2023
How to Fix “The Character Encoding Was Not Declared” Error
Site Audit Issues
How to Fix “The Character Encoding Was Not Declared” Error
Ivan Palii
Sep 13, 2023
close