Gzip is a file compression method that is used to reduce the file size of text files, such as HTML, CSS, and JavaScript files.
Gzip works by compressing the data in the file before it is sent over the network, and then decompressing it on the client side.
What exactly is Gzip Compression
The simple’s way to explain Gzip compression is by imagining you ordered a new dinner table. Once it arrives it will be packaged with multiple parts that you will need to put all the pieces together to build the table.
Gzip compression works in a similar way but with computer bytes, the server will compress streams of bytes such as spacing within HTML, CSS or JS files and send them across the web.
Once the files are downloaded by your browser, the browser will start uncompressing these files. This simple feature can yield significant page speed improvements and reduction to page size.
This simple feature can yield significant page speed improvements and reduction to page size which can help improve SEO performance.
How does Gzip work?
- Gzip uses a lossless compression algorithm to compress the data in a file.
- This means that the original data can be recovered exactly after it has been compressed and decompressed.
- Gzip uses a technique called Huffman coding to compress the data, which is a method for representing symbols in a file with a minimum number of bits.
Benefits of using Gzip:
- Reduced file size: Gzip can significantly reduce the file size of text files, which can lead to faster page load times and reduced bandwidth usage.
- Improved performance: Gzip can improve the performance of a website by reducing the amount of data that needs to be transferred over the network.
Implementing Gzip:
- Gzip can be enabled on a server through the use of a module or extension, such as mod_deflate for Apache or ngx_http_gzip_module for Nginx.
- It can also be enabled on a CDN level or using a plugin if using a web platform such as WordPress.
- Additionally, you can check if your server supports gzip by sending a request header “Accept-Encoding: gzip” and check the response header “Content-Encoding: gzip”
Browser support:
- Most modern web browsers support Gzip, but it’s important to check for compatibility before implementing it.
- Gzip can be checked on browser by visiting a website and check the response headers for “Content-Encoding: gzip”
Enabling Gzip Compression with .htaccess
The code below should be inserted into your .htaccess file that usually lives in the root of your website.
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
# For Olders Browsers Which Can't Handle Compression
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Hosted with Koerge?
If your website is hosted with Koerge you won’t need to do anything. Gzip compression is enabled by default for all our customers, therefore no technical knowledge or changes are required to enable this feature.