How to enable GZIP compression using .htaccess file

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/vnd.ms-fontobject
  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/vnd.microsoft.icon
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE text/html
</IfModule>
				
			

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.

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.

Odebírat
Upozornit na
guest
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