3 Easy Ways to Enable GZIP Compression for a Faster Website

    Slow websites can cause many problems. It can make your website difficult to use, frustrate customers, drive away potential customers, and impact your brand reputation. You can speed up your WordPress website by removing all unwanted resources. You can also compress any resources, that are necessary for your website, to speed up the website. GZIP compression is one of the easiest and most efficient methods to do this.

    Google PageSpeed insight warns you to Enable Compression if Gzip compression has not been enabled on your WordPress site. You can resolve this warning in one of three ways. A caching plugin that supports Gzip is the first and easiest way to fix the warning.

    What is GZIP Compression?

    GZIP compression compresses data files before they are sent to users’ browsers. This speeds up the file download process, which will make your website more responsive. This reduces the size of HTML, CSS, and JavaScript files to make them more quickly accessible for users.

    GZIP compression doesn’t work with images. However, certain image files such as MPEGs or WAVs can be compressed well using GZIP. If you compress media files, like MP3s, they may increase in size.

    What does GZIP Compression actually do?

    GZIP uses lossless compression. That is, the original data can be restored completely during unpacking. It uses the DEFLATE algorithm which combines both the LZ77 algorithm and the Huffman algorithm.

    GZIP compression compresses raw data losslessly, and it works best for text-based assets, such as HTML, CSS, JS. Compression can reduce file sizes as much as 70%, depending on how large the data is.

    A browser checks to see if a webserver has GZIP enabled before it requests the webpage. It will receive the GZIP version that is smaller if enabled. If not, it will still receive the page but only the uncompressed version.

    How to Find Out If GZIP Compression Has Been Enabled?

    Simply go to this GZIP tester tool (, and enter your URL to check if GZIP has been enabled on your website. You will receive a message indicating that GZIP is enabled on your site if it is.

    Also, you can check to make sure your browser is receiving the content-encoding GZIP response from the server.
    Chrome: Open your website in a browser tab. Right click anywhere on the page, and then click Inspect. It will open up developer tools. Navigate to Network tab, and then click on the homepage name. Select the Headers tab and scroll down to locate the Response Headers section.

    3 Ways to Enable GZIP Compression

    GZIP compression is implemented on the web server. The configuration process will vary depending on your hosting provider’s server architecture. It is recommended that you check the documentation of your hosting provider to see if GZIP compression has been enabled on your web server. Modifying server files may be forbidden by your host.

    1. Enable GZIP Compression in WordPress

    Use a caching plugin to enable GZIP compression if you have a WordPress website. It is much simpler and safer than directly editing the .htaccess file. There are several WordPress plugins that make it possible to enable WordPress GZIP compression:

    2. Enable GZIP Compression in Nginx

    Nginx is an open-source web server that supports GZIP compression. Here’s a codesnippet to enable it. The code snippet below must be included in your site’s nginx.conf file. It should be located in the “http” subsection. You can also put this code snippet into the server or location configuration blocks, but it is generally preferred to place it in the http section.

    gzip on;
    gzip_types text/plain text/css text/javascript image/svg+xml image/x-icon application/javascript application/x-javascript;
    gzip_min_length 1000;
    gzip_vary on;
    gzip_proxied no-cache no-store private expired auth;
    gzip_diable “MSIE [1-6];

    After saving and closing the file, restart Nginx. The following command will do the trick:

    sudo service nginx restart

    3. GZIP compression for Apache can be enabled by editing the .htaccess file

    To enable GZIP compression on Apache web hosts, you’ll need to edit the file .htaccess. You can find this file in your WordPress root directory, using File Transfer Protocol (FTP), or your file manager. Editing the .htaccess file is required for most WordPress GZIP compression methods. You can enable GZIP with two Apache mods, but mod_deflate has the best documentation and is most well-supported. To enable mod_deflate, add:

    <IfModule mod_deflate.c>
    # Compress HTML, CSS, JavaScript, Text, XML and fonts
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/
    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
    # Remove browser bugs (only needed for really old browsers)
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    Header append Vary User-Agent

    And to enable mod_gzip add:

    <ifModule mod_gzip.c>
    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
    mod_gzip_item_include mime ^application/x-javascript.*
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_include handler ^cgi-script$

    It is important to backup your .htaccess and make sure that the module filter is present on your server before you can use either mod.

    Gzip compression can be a simple, but powerful tool that can make all the difference. Gzip compression is easy to use, so you don’t have to miss out. Google and your visitors will be grateful.

    Latest articles


    Related articles

    Leave a reply

    Please enter your comment!
    Please enter your name here

    14 + five =