How to Enable and Test GZIP Compression on Your Website


Last Updated : |  

Apache servers come with the GZIP compression program already integrated, making it a convenient choice for many website owners. Enabling GZIP compression is a straightforward process that can be done quickly through the .htaccess file. With GZIP activated, your files are compressed, allowing for faster delivery to users.

Enable GZIP with the htaccess

There are various methods to enable GZIP compression, but in this post, we'll focus on the .htaccess variant, a popular and efficient way to utilize GZIP on Apache servers. Here's why and how you can take advantage of GZIP:

  • Why Use GZIP?: GZIP compression reduces the size of files, making them faster to transfer. This can lead to improved loading times and a better user experience on your website.
  • How to Activate GZIP with .htaccess: Enabling GZIP through the .htaccess file is a simple process. By following a few steps, you can have GZIP activated on your Apache server, enhancing your site's performance.

Stay tuned as we delve into the specific steps to enable GZIP compression using the .htaccess method on Apache servers.

Enable GZIP with the .htaccess File

Enabling GZIP compression on Apache servers often involves using the DEFLATE algorithm, which is a key part of GZIP encoding. This algorithm consists of two main components: LZ77 and Huffman coding. To activate GZIP compression, you can use the AddOutputFilterByType directive within the .htaccess file to compress all applicable content in the output.

Here's a brief overview of what this process might look like:

  • Understanding DEFLATE: DEFLATE is vital for GZIP encoding and plays a central role in compressing files.
  • Activating GZIP: You can enable the GZIP module in the Apache configuration file. Though it should already be enabled, you can verify and make changes through the console (Terminal) if needed.
  • Utilizing .htaccess: By adding specific directives to the .htaccess file, GZIP compression can be applied across various content types, improving the speed and efficiency of your site.

In the following sections, we'll go into more detail on how to enable GZIP using the .htaccess file and the specific commands you'll need.

USERNAME$ nano /etc/httpd/conf/httpd.conf# Deactivated
# LoadModule deflate_module modules/
# Activated
LoadModule deflate_module modules/

     0  <IfModule mod_deflate.c>  1      #DeflateCompressionLevel 9  2      # Set DEFLATE filter  3      SetOutputFilter DEFLATE  4      # Text and applications  5      AddOutputFilterByType DEFLATE text/html  6      AddOutputFilterByType DEFLATE text/css  7      AddOutputFilterByType DEFLATE text/javascript  8      AddOutputFilterByType DEFLATE text/plain  9      AddOutputFilterByType DEFLATE text/xml  10      AddOutputFilterByType DEFLATE text/json  11      AddOutputFilterByType DEFLATE text/vtt  12      AddOutputFilterByType DEFLATE application/js  13      AddOutputFilterByType DEFLATE application/javascript  14      AddOutputFilterByType DEFLATE application/rss+xml  15      AddOutputFilterByType DEFLATE application/atom+xml  16      AddOutputFilterByType DEFLATE application/  17      AddOutputFilterByType DEFLATE application/xhtml+xml  18      AddOutputFilterByType DEFLATE application/xml  19      AddOutputFilterByType DEFLATE application/json  20      AddOutputFilterByType DEFLATE application/ld+json  21      # Compress SVG images  22      AddOutputFilterByType DEFLATE image/svg+xml  23      # Fonts  24      AddOutputFilterByType DEFLATE font/otf font/ttf  25      # Prevent web browsers reporting improperly compressed content from receiving compressed content  26      BrowserMatch ^Mozilla/4 gzip-only-text/html  27      BrowserMatch ^Mozilla/4\.0[678] no-gzip  28      BrowserMatch \bMSIE !no-gzip !gzip-only-text/html  29      # Logging (optional)  30      #DeflateFilterNote Input instream  31      #DeflateFilterNote Output outstream  32      #DeflateFilterNote Ratio ratio  33      #LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate  34      #CustomLog logs/deflate_log deflate  35      # For proxies  36      <IfModule mod_headers.c>  37          Header append Vary User-Agent  38      </IfModule>  39  </IfModule> 

    You can also place specific lines at the end of your Apache configuration file or directly within the .htaccess file to enable GZIP compression. By doing so, you can include almost all file types to compress them in the output via GZIP. This is an essential step in optimizing your website's performance.

    Below, you'll find a tool to verify whether the GZIP compression is now effective. It's best to test it first without GZIP, and then with, to see the difference. I'm 100% sure that activating GZIP compression will work, and you'll likely notice improved results with Google Page Speed. The use of GZIP is a proven method to enhance your site's loading times and overall user experience.

     mod DEFLATE

    Set and Use Browser Cache with GZIP

    Having activated GZIP, it's now time to leverage the full potential of browser caching. By setting the expiration date for various resources and utilizing browser cache alongside GZIP, you can gain additional speed advantages for your website.

    Here's what you need to know about combining browser cache with GZIP:

    • Why Use Browser Cache with GZIP?: Browser caching stores static files in the visitor's browser, allowing for quicker loading times on subsequent visits. Combining this with GZIP compression further enhances the speed and performance of your site.
    • Setting Expiration Dates: By defining specific expiration dates for your applications, you ensure that the browser cache works efficiently with GZIP. This results in better ratings and a more optimized user experience.
    • Optimizing Settings: The settings provided here have proven effective in my experience, but there might be room for further optimization. If you have any ideas or concrete solutions to enhance the combination of browser cache and GZIP, your insights would be welcomed.

    Used Browser Cache

       0  <IfModule mod_expires.c>  1      ExpiresActive ON  2      # Default 1 day unless otherwise defined  3      ExpiresDefault "access plus 1 day"  4      # Text  5      ExpiresByType text/html "access plus 1 hour"  6      ExpiresByType text/cache-manifest "access plus 1 hour"  7      ExpiresByType text/css "access plus 1 year"  8      ExpiresByType text/javascript "access plus 1 year"  9      # Application  10      ExpiresByType application/xml "access plus 1 hour"  11      ExpiresByType application/json "access plus 1 hour"  12      ExpiresByType application/xhtml+xml "access plus 1 hour"  13      ExpiresByType application/rss+xml "access plus 1 hour"  14      ExpiresByType application/atom+xml "access plus 1 hour"  15      ExpiresByType application/ "access plus 1 year"  16      ExpiresByType application/javascript "access plus 1 year"  17      ExpiresByType application/pdf "access plus 1 month"  18      # Image  19      ExpiresByType image/gif "access plus 1 year"  20      ExpiresByType image/png "access plus 1 year"  21      ExpiresByType image/apng "access plus 1 year"  22      ExpiresByType image/jpg "access plus 1 year"  23      ExpiresByType image/jpeg "access plus 1 year"  24      ExpiresByType image/icon "access plus 1 year"  25      ExpiresByType image/ico "access plus 1 year"  26      ExpiresByType image/webp "access plus 1 year"  27      ExpiresByType image/svg+xml "access plus 1 year"  28      # Audio  29      ExpiresByType audio/ogg "access plus 1 year"  30      # Video  31      ExpiresByType video/ogg "access plus 1 year"  32      ExpiresByType video/mp4 "access plus 1 year"  33      ExpiresByType video/webm "access plus 1 year"  34      # Webfonts  35      ExpiresByType font/truetype "access plus 1 year"  36      ExpiresByType font/opentype "access plus 1 year"  37  </IfModule> 

      By strategically using browser cache with GZIP, you can create a seamless and responsive web experience. It's another step in fine-tuning your website's performance and making sure you rank well in search engine results.

       mod EXPIRES

      Test Your GZIP Compression Now!

      Not sure if your GZIP compression is set up correctly? Want to see how much you're saving with compression? Our easy-to-use  All in One SEO Tool SEOLIC gives you instant insights into your website's GZIP performance and many many more. Click the button below to test your GZIP compression and get detailed results in seconds. Your path to a faster, more optimized website starts here!

      Once you've added the necessary lines to your .htaccess file and activated GZIP compression, it's essential to test whether everything is functioning correctly. You'll want to verify that the content is indeed compressed, how much it's compressed when using GZIP, and compare the results to when it's not compressed.

      Here's how you can approach testing GZIP:

      • Verify Compression: Ensure that GZIP compression is working as intended. You should be able to see the difference in file sizes when compressed with GZIP versus when not compressed.
      • Evaluate Effectiveness: If GZIP is working correctly (which it should for 99% of the solutions mentioned above), you've successfully activated GZIP compression on your site. I'm pretty confident that these methods will work for anyone who employs them.

      Congratulations! You've taken a significant step in optimizing your website's performance by enabling GZIP.


      Enabling GZIP compression is a powerful way to enhance your website's speed and efficiency. Through careful implementation and testing, GZIP can provide substantial benefits in terms of loading times and user experience. This guide has walked you through the process of activating GZIP on Apache servers, utilizing .htaccess, and combining GZIP with browser caching. By following these steps, you're well on your way to a more responsive and highly optimized website. Happy compressing with GZIP!


      Your Comment

      * This fields are required, email don't publish

      This field is optional
      Fill this field link your name to your website.

      Data entered in this contact form will be stored in our system to ensure the output of the comment. Your e-mail address will be saved to determine the number of comments and for registration in the future

      I have read the Privacy policy and Terms. I Confirm the submission of the form and the submission of my data.
      tnado © 2023 | All Rights Reserved
      Made with by prod3v3loper