A detailed explanation of how the HTTP/2 protocol works
I recommend readingHTTP tutorialFirst
HTTP/2 is the current version of the HTTP protocol. Published by the IETF (Internet Engineering Task Force) committee in 2015, it has now been widely adopted due to its unique features.
HTTP/2 is more performant than HTTP/1.1 (the latest HTTP version available at the time).
The slowdown feature provided by HTTP/2 is very attractive, so it was quickly adopted-by making simple changes to the web server (because HTTP/2 is 100% backward compatible with HTTP/1.1), your website and web application can now Normal work is automatically faster, which in turn is beneficial to your users and SEO (because speed is a key factor in ranking).
How is HTTP/2 so much faster than HTTP/1.1? There are many reasons, all of which are to reduce the inefficiency of the previous version and introduce features that enable the browser to provide resources more quickly.
The main functions of the new version of the agreement are:
- Request and response multiplexing
- Effectively compress HTTP headers
- Server push
- Binary communication
Before HTTP/2, each TCP connection could only provide one response at a time.
TCP is the basic protocol on which HTTP is built. TCP stays at the transport layer, while HTTP stays at the application level.
Enable HTTP/2 request/response multiplexing on top of a single TCP connection, allowing the server to use the same connection to serve multiple requests, thereby achieving faster communication.
This is a single change that will bring huge benefits to your application and make some optimization techniques obsolete, including image sprites (used to merge multiple images into one image, and then use special CSS technology to make it " Demultiplexing")) and domain fragmentation, which is another hacker used to prevent browsers from limiting the number of simultaneous connections to the same domain.
Server push is a feature that allows multiple responses to a single request. Since the server knows that when the resource is requested, the client will subsequently request other supplementary resources (such as CSS, JS, images linked to the page), so the server can decide to send them immediately.
The server does not need to send HTML, but waits for the browser to parse it and trigger other requests to obtain assets, but can push it completely.
The server can also decide to send resources that may be needed in future requests, optimize the next page load in advance and put it into the client cache.
Please note that server push may also have its own disadvantages-for example, you may take unnecessary risks to send too much data to the client (may be cached on the client), so use it with caution
HTTP/1.1 uses text-based communication. HTTP/2 uses binary communication, which has some advantages, including higher parsing efficiency, less error-prone and more compact.
What will happen in the future?
HTTP/3Under development and will be based onHTTP-QUIC, An experimental project.
QUIC is a protocol based on UDP (rather than TCP) at the transport layer, which means that compared to HTTP/2 and HTTP/1.x, HTTP/3 will be based on a completely different technology stack.
More web tutorials:
- Introduction to WebSockets
- How HTTP requests work
- List of HTTP request headers
- List of HTTP response headers
- HTTP and HTTPS
- What is RFC?
- HTTP protocol
- HTTPS protocol
- The curl guide for HTTP requests
- HTTP cache
- List of HTTP status codes
- What is CDN?
- HTTP/2 protocol
- What is the port
- DNS, Domain Name System
- TCP protocol
- UDP protocol
- Introduction to REST API
- How to install a local SSL certificate in macOS
- How to generate a local SSL certificate
- How to configure Nginx for HTTPS
- A simple Nginx reverse proxy for serving multiple Node.js applications from subfolders
- What is a reverse proxy?