GZIP Compression: Speed Up & Optimize Your Website
To accomplish a fast webpage load on your own WordPress site, it is necessary to decrease the size of your website’s webpages. Enabling it to help decrease the size of your web pages. It will significantly reduce the quantity of time to download the webpage. Further, reduce data utilization for your client, and enhance the time to 1st render of your webpage(s).
Nowadays, All browsers support it. Further, They automatically negotiate it for all requests of HTTP/HTTPs. In this post, we will talk about it in length. And, provides information on how to check and allow it on your web server.
How does the Compression Scheme Negotiation happen Between Browser & Server?
Browser Gzip Request & Server Response Snapshot
The whole negotiation between browser & server is done in simple two steps.
1. The browser transmits HTTP request with header informing the server that it accepts compressed content. It can be either gzip and deflate. These are 2 well-known compression schemes available for compression. Ex: Accept-Encoding: gzip, deflate
For Content-Encoding, Accept-Encoding filed is used & for Transfer-Encoding, the field TE is used.
GET /encrypted-area HTTP/1.1 Host: www.auniqueweb.com Accept-Encoding: gzip, deflate The “Accept-encoding” header is only a demand by the internet browser, not really a demand.
2. Then, The server transmits a reply containing one or more compression schemes it supports. if the content material is in fact in compressed form, It sends a response with Content-Encoding: gzip. In fact, The outgoing request data may be compressed by one or more methods supported by both parties. So, the server will add a Content-Encoding or Transfer-Encoding field in the HTTP response with the available compression schemes, separated by commas.
HTTP/1.1 200 OK Date: mon, 26 June 2016 22:38:34 GMT Server: Apache/126.96.36.199 (Unix) (Red-Hat/Linux) Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT Accept-Ranges: bytes Content-Length: 438 Connection: close Content-Type: text/html; charset=UTF-8 Content-Encoding: gzip
If the server doesn’t send the content-encoding response header, this means the file isn’t compressed. In other words, If the server doesn’t want to send compressed content to the web browser, the web browser has to put up with the heavy standard version.
The most tricky part of this exchange is the browser and server knowing upfront it’s ok to send a zipped file over.
The compression method used by the web server solely depends on the internal settings of the web server. Further, it may also depend on the internal architecture of the site.
How compressed files work on the web?
For example, When a request is made by a browser for a file of your website, your web server returns the smaller compressed file if the browser indicates that it understands the compression. Nowadays, All most All browsers understand and accept compressed files.
How GZIP Compresses data of a web page?
Gzip locates similar strings within document types such as CSS and HTML files. It replaces those strings temporarily with some placeholders. It is to make the overall file size smaller.
Do you know the reason why these compressions work so well in a web environment?. It is because these document types such as CSS files and HTML files use a lot of repeated text and have loads of white space. Since It compresses common strings, it may reduce the size of pages and style sheets by up to 60-70 %!
If in case, you can’t change your .htaccess file, you may use PHP to return compressed content. Also, Give your HTML file a .php extension and add below code to the top of it (for PHP).
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
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/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 Older Browsers Which Can’t Handle Compression
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0 no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
If you wish to download file, you may down it from Here.
1. If in case your server does not support mod_deflate, you may try the mod_gzip scheme.
2. In case you don’t have access to web server, you may use plugins to enable it for your website.
b) Compression via mod_deflate
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
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$
Once it is updated, compression will be allowed.
Option 5. Enable GZIP on NGINX
If you are using NGINX, simply add the below code to your nginx.conf document.
gzip_disable “MSIE [1-6]\.(?!.*SV1)”;
Option 6. Enable GZIP on IIS
If you are working on IIS webserver, we recommend looking into Microsoft’s guide about how to enable compression. Microsoft IIS broadly has two various kinds of compression. They are dynamic and static.
Option 7. Enable compression on Litespeed webservers
The correct way to allow compression in Litespeed is to accomplish it through the configuration under “tuning”.
Just go below to “enable compression” and check to see if it is on. In case if not, click “edit” & then choose to turn it on. And, look over there for several compression options that are nearby.
GZIP is quite common nowadays. In fact, it is enabled by default on all servers. All most all modern browsers handle the “content-encoding: gzip” HTTP response header. All modern browsers like chrome, firefox support it.
HTTP response size may be reduced by using Compression. GZIP is the most well-known and effective compression technique available for HTTP response. It generally decreases the response size to 60-70%.
Therefore, webmasters need to make sure that the server is properly configured to provide the compressed source when requested by your client’s browser. It means that it takes much less time to load your web pages, and very less bandwidth is used over all.