Gzip compression fails on a Linux instance

更新时间:
复制 MD 格式

On some older Web Hosting instances, Gzip compression is not enabled by default. In other cases, compression may not be configured for certain file types on your instance. As a result, you might find that Gzip compression fails to apply to your site, even after you configure it. This topic shows you how to fix this issue.

Problem description

You have configured Gzip compression for a Web Hosting instance that runs a Linux operating system, but it is not being applied to your website.

Causes

  • Compression is not enabled by default on some older Web Hosting instances.

  • Compression is not configured for certain file types.

Solution

  1. Check if Gzip compression is enabled on your Web Hosting instance.

    1. Open your website in a browser.

    2. Press F12 to open the browser's developer tools.

    3. Click the Network tab.

    4. Click a file under the Name column. In the Response Headers section on the right, check if the value of the Content-Encoding header is gzip.

      • Yes: Gzip compression is enabled. Proceed to the next step.

      • No: Gzip compression is not enabled. Please submit a ticket.

  2. Use an FTP client to connect to your Linux-based Web Hosting instance.

    For more information, see Use FileZilla to manage files.

  3. In the /htdocs directory of your Linux-based Web Hosting instance, locate the .htaccess file.

    Note

    The .htaccess file is hidden by default. To display hidden files in your FTP client, see Display hidden files in the file list of an FTP client. To modify the .htaccess file, download it from the Remote site panel, edit it, and then upload it back.

  4. In the .htaccess file, use the DEFLATE algorithm to compress specific file types.

    The following sample code compresses common file types, such as plain text, HTML, XML, and CSS files:

    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/x-httpd-php
    AddOutputFilterByType DEFLATE application/x-httpd-fastphp
    AddOutputFilterByType DEFLATE image/svg+xml