How to enable GZIP compression using .htaccess file

Last updated December 6th, 2023 06:23

Modern websites contain many elements besides images that are not immediately visible to the average user. These can include fonts, CSS files, and many other website elements. All of them must be sent from the server to the user’s browser. The larger the amount of data that needs to be transferred, the longer it will take for the website to load. Sometime caching plugins can help with website loading times by actively storing data in the cache. Another method that can significantly improve website loading times is the use of GZIP compression. Let’s take a look at how to enable GZIP compression using .htaccess file.

How to enable GZIP compression using .htaccess file

Enabling GZIP compression using the .htaccess file can reduce the size of individual website elements that need to be downloaded. The compression process involves compressing data on the server side, which reduces its size. The compressed data then travels to the user’s browser in the usual way, where it is decompressed and displayed as web pages.

There is a direct trade-off between speed and performance, which makes sense. While website loading times are reduced, the performance demands placed on the server increase. The server must compress data before sending it. Also the browser must decompress data before displaying it, so the data does not travel in its “raw” state. This is the compression and decompression process.

Jak zapnout GZIP kompresi pomocí souboru .htaccess

Connecting to FTP

If GZIP compression is supported on the server, it is usually enabled by editing the .htaccess file, which is available on FTP (Linux servers). You can connect to FTP using an FTP client, such as Total Commander.

The .htaccess file and its editing

To enable GZIP compression, you must first connect to FTP and find the .htaccess file. You can usually find this file in the root folder of your website, where other data that is displayed under the domain in the browser is located. If you are using the Total Commander FTP client, you can easily edit the file by selecting it with your mouse and pressing the F4 key.

Directives to insert into the .htaccess file

You can copy the directives that enable GZIP compression and insert them into the .htaccess file below.

					<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/json
  AddOutputFilterByType DEFLATE application/
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE application/font-sfnt
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE text/html

After inserting these directives into the .htaccess file, save it and test your website. Additionally, you can test its speed using online tools such as Google PageSpeed Insights. Before testing the speed and performance of your website or whether GZIP compression affects the speed of your website, I recommend clearing the cache if any cache plugin is used on the website.

The website is created with care for the included information. I strive to provide high-quality and useful content that helps or inspires others. If you are satisfied with my work and would like to support me, you can do so through simple options.

Byl pro Vás tento článek užitečný?

Klikni na počet hvězd pro hlasování.

Průměrné hodnocení. 0 / 5. Počet hlasování: 0

Zatím nehodnoceno! Buďte první

Jak užitečný vidíte tento článek.

Sledujte mě na sociálních médiích.

Je mi líto, že pro Vás nebyl článek užitečný.

Jak mohu vylepšit článek?

Řekněte mi, jak jej mohu zlepšit.


Subscribe to the Newsletter

Stay informed! Join our newsletter subscription and be the first to receive the latest information directly to your email inbox. Follow updates, exclusive events, and inspiring content, all delivered straight to your email.

Upozornit na
0 Komentáře/ů
Vložené zpětné vazby.
Zobrazit všechny komentáře.

Pokud mi chcete napsat rychlou zprávu, využije, prosím, níže uvedený
kontaktní formulář. Děkuji.

Další Kontaktní údaje