Comparison of HTTP and HTTP/2
This comparison blog post is to show why you should move from HTTP to HTTPS and why you should add support to HTTP/2. Before comparing HTTP vs HTTP/2. Lets see what is HTTP first.
Hypertext Transfer Protocol (HTTP)
HTTP is the set of rules for communication on the World Wide Web (www). HTTP is an application protocol which runs on top of the TCP/IP layer. When a user requests a web page in the browser, HTTP takes the request and establish the connection between the web server and a client.
Points to note
- HTTP is Synchronous.
- Data sent over HTTP are via plan text. Thus not secure. Man in the middle attack is possible.
- Multiple TCP connections: increase in number of round trips for multiple TCP connections.
- HTTP is stateless protocol, because each command is executed separately without the knowledge of the previous command.
Site using http (non-secure) screenshot:
Hypertext Transfer Protocol Secure (HTTPS)
HTTPS is the secured version of the HTTP. Communication between web server and the client are encrypted by Transport Layer Security (TLS) or by Secure Socket Layer (SSL).
site using https (secure) screenshot:
HTTP vs HTTPS test
Each test loads 360 unique, non-cached images (0.62 MB total). After multiple tests, HTTPS were able to load 37% faster than unsecured HTTP. One more reason to move from HTTP to HTTPS.
Results screenshot
Points to note
- Secure connection. All the data sent over HTTPS are encrypted.
- Loads faster than the unsecured HTTP.
- Service Workers, Geo Location, Camera API etc are only supported in HTTPS.
Hypertext Transfer Protocol 2 (HTTP/2)
HTTP/2 is next version of HTTP. HTTP/2 solves many of the HTTP/1.1 problems.
Points to note
- Single TCP connection: Thus less number of round trips for TCP connections.
- Binary: Server can parse easily without the need for converting from text to binary.
- Multiplexing: Can make multiple requests at the same time (max of 6 - 8)
- Header Compression: HTTP header size is compressed thus size is reduced.
- Server Push: Server can send resources to the client which was not yet requested.
- Request Prioritization: Each request can be prioritized to request more important resources first.
HTTPS vs HTTP/2 test
This test is similar to the previous test but with HTTP/2 support. Each test loads 36 unique, non-cached images (292 KB total). After multiple tests, HTTP/2 were able to load 80% faster than HTTPS.
Results screenshot:
Browser Support for HTTP/2
Source caniuse.com
CDN's which supports HTTP/2
Conclusion
HTTP/2 let us increase the performance of our site without any need for shredding, spriting, concatenating etc. This doesn't mean that we shouldn't do all that. But it clearly shows us the importance of moving from HTTP/1.1 to HTTP/2.
Thanks for reading my post. If any questions comment below or if you liked my post share it 😃