HTTP2 vs HTTP 1.1
--
What is HTTP?
Hypertext Transfer Protocol (HTTP) is an application protocol that is, currently, the foundation of data communication for the World Wide Web.
HTTP is based on the Client/Server model. The client/Server model can be explained as two computers, Client (receiver of service) and Server (provider of service) that are communicating via requests and responses.
A simple and abstract example would be a restaurant guest and a waiter. The guest (Client) asks (sends request) a waiter (Server) for a meal, then the waiter gets the meal from the restaurant chef (your application logic) and brings the meal to the guest.
What is HTTP1.1?
Http1.1 is the most common method of getting data from the server by opening a TCP connection asking for something, like index.html, then closing it back again so, many connections are opened individually, to get various files that a site requires to be displayed in the device properly and that is very slow as many connections are opened and for each thing, a get request is generated.
What is HTTP/2?
In 2015, the Internet Engineering Task Force (IETF) released HTTP/2, the second major version of the most useful internet protocol, HTTP. It was derived from the earlier experimental SPDY protocol.
Differences between HTTP1.1 and HTTP2?
left is http1.1 right is http2
- HTTP/1.1 opens a TCP link every time it sends a request while HTTP/ 2 just has one TCP link over which data is sent.
- HTTP/1.1 asks for each thing that it requires to display the site, but whereas HTTP/2 uses server pushing which means that when HTTP/2 asks for “index.html” or any file server will also give as much data as it can over the same link because it knows that you also need those files to display the site.
- HTTP/1.1, as asks for lets, say an image, the probability is that in HTTP/2 has already got the image dude to server pushing and because there is one TCP link only, The image is sent much faster and loads much faster.
Benefits of HTTP/2?
HTTP/2 is much faster because of the various methods it utilizes to properly display a site.
- Domain sharding is not required
- Single tcp connection, instead of many.
- Binary protocol instead of textual protocols.
- Server push
- increased security, like browsers, only support HTTP/2 over an encrypted connection.
- Faster loading times
You see the first thing that they have improved is that instead of opening multiple TCP connections, it opens one connection and gets all the files through that, but does that make it much faster, no that does decrease the time it takes for the things to come through but, the main reason is server pushing, so you see just thing that the server knows that to load the site you will need index.html, script.js, and all the other files so once when the device asks for just index.html, the server also pushes as much data as possible without being asked for and that makes it faster, so when the device asks for index.html, the server will push, script.js any images it finds, And style.css and as much data it can over that single connection. That does also decreases the time required for loading an image as they are already pushed.