Now a days everyone want to make sure that, their websites are loading in fraction of seconds including all its assets ( css, js, images etc ). Eventually we call it as performance. A site's performance is not only depending upon the server side or javascript code. Possibly your web server can do something about the performance. If We are trying to load a large size image in a page & client's browser may take more time to render the page based on the bandwidth.
Without doing any code changes, we can partially achieve that by simply upgrading our Apache web server's HTTP version to HTTP 2.0
and enabling Gzip compression
. Here we will talk about, what are the benefits of using HTTP 2.0 & Gzip. As well as, we will see, how to configure those in Apache web server.
HTTP/2 is the evolution of the world's most successful application layer protocol, HTTP. It focuses on making more efficient use of network resources. It does not change the fundamentals of HTTP. it dramatically improves website performance with no downside.
It can be used over Secure (HTTPS) with TLS and non-secure (HTTP) protocols, but all the major browsers like Mozilla, Chrome, IE, Safari, Edge had stated that they will support HTTP/2 only with Secure Version of HTTP means HTTPS with TLS). Thus HTTPS is mandatory for using HTTPS over these browsers.
LoadModule http2_module modules/mod_http2.so
This module available from apache version 2.4, By default the module not enabled, we should enable that. To enable the HTTP 2.0 module goto apache\conf\httpd.conf file, Find LoadModule http2_module modules/mod_http2.so
. If the line prefix with # symbol then remove the # and then save.
Protocols h2 http/1.1
(h2 is HTTP/2 over TLS). Protocols h2 h2c http/1.1
(h2c is HTTP/2 over TCP)+ The order of protocols mentioned is also relevant. By default, the first one is the most preferred protocol. When a client offers multiple choices, the one most to the left is selected. In Protocols http/1.1 h2
, the most preferred protocol is HTTP/1 and it will always be selected unless a client only supports h2. Since we want to talk HTTP/2 to clients that support it, the better order is Protocols h2 h2c http/1.1
There is one more thing in ordering of your options: the client has its own preferences, too. If you want, you can configure your server to select the protocol most preferred by the client: ProtocolsHonorOrder Off
mod_deflate
module provides the DEFLATE output filter that allows the output from your server to be compressed before being sent to the client over the network. mod_deflate is the replacement of mod_gzip
which was used with an older version of Apache.The main reason it is important is because it reduces the time it takes for a website to transfer the page files and style sheets which ultimately reduces the load time of your website.
How compressed files work on the web ?When a request is made by a browser for a page from your site your webserver returns the smaller compressed file if the browser indicates that it understands the compression. All modern browsers understand and accept compressed files.
How to configure Gzip compression: #LoadModule deflate_module modules/mod_deflate.so
and LoadModule filter_module modules/mod_filter.so
) module.AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
.htaccess
file in the site root.