Get Ready for HTTP2
History of HTTP:-
Hypertext Transfer Protocol (HTTP) is a communications protocol. It is used to send and receive webpages and files on the internet. It was defined in 1991 and currently version 1.1 is used world-wide.
Today, the amount of data required to load an average website’s homepage ranges between 1.8 MB – 2.0 MB. This data can be images, javascript, css files etc.
It is noticed that HTTP 1.1 doesn’t perform well when retrieving large number of resources required to display a modern website. So, in 2009 two google engineers decided to address some of these HTTP 1.1 issues and started working on a project named SPDY (pronounced speedy).
SPDY:-
SPDY has following features:-
- Multiplexing - Allow concurrent requests across a single TCP connection.
- Assets can be prioritized by the browsers, so that resources which are important for display of webpage can be sent by the server first.
- Compression and reduction of HTTP headers.
- Implementing server push – A server can push vital resources to the browser before being asked for them.
- It is Binary while as HTTP 1.1 is textual.
- SPDY requires an encrypted (HTTPS) connection between the browser and server.
SPDY is not replacing HTTP, rather, it’s a tunnel for the protocol and modifies the way existing HTTP requests and responses are sent. It requires support from both the server and the browser connecting to that server.
The core developers of SPDY have been involved in the development of HTTP/2 too.
As of February 2015, Google has announced that following the recent final ratification of the HTTP/2 standard, support for SPDY would be deprecated, and support for SPDY would be withdrawn completely in 2016, so all other browsers (Firefox, IE and Opera) will follow. Safari, will join that group later this year (2016) with the launch of Safari 9.
HTTP/2:
HTTP/2 is built on the success of SPDY and majority of SPDY’s objectives are met in HTTP/2. The requirement for an HTTPS connection has been dropped. So, all of the browser vendors have decided to implement HTTP/2 for TLS (https) connections only. Some implementations have stated that they will only support HTTP/2 when it is used over an encrypted connection, and currently no browser supports HTTP/2 unencrypted.
HTTP/2 is backwards-compatible with HTTP/1.1, so it is possible to ignore it completely and everything will continue to work as before.
Going forward as more servers/browsers will start to use HTTP/2 then our current applications which are very well optimized according to best practices, will start to seem slower than websites optimized for the new protocol.
Modern versions of all major browsers support HTTP2 (check).
What needs to be done for HTTP/2:-
- Move to HTTPs:-
If you are planning for revamp of old website or building a new one then you should make sure to move to HTTPs as first step.
- Multiple image files to Sprite is not required because of multiplexing ability of HTTP/2.
- Concatenating of css and javascript files was a best practice in HTTP 1.1 but user might download all the css and script which is actually not required on that particular page. Now, organizing the assets during development and loading only required assets is far better approach.
- Remove Domain Sharding:-
Loading multiple resources from multiple domains is called domain sharding. Since HTTP/1.1 has restriction of number of open connections, so website owners use domain sharding. In HTTP/2, there is no need of it because you can load as many number of resources as you need. In fact, this technique will likely hurt performance because it creates additional TCP connections and hinders HTTP/2 from prioritizing resources.
When to switch to HTTP/2:-
Remember that HTTP/2 is backward compatible, so you don’t actually need to make any changes to make your website compatible with HTTP/2. The only decision you need to make is when to optimize your website for it.
Once your website is hosted on a server which supports HTTP/2 then the decision of either optimizing your website for HTTP/1.1 or optimizing it for HTTP/2 depends on the protocol supported by majority of your users.
Demo:-
References:-