About HTTP/2 server push
Before talking about HTTP/2 server push, we must first know that HTTP/2 is designed to solve many shortcomings of HTTP/1.x. Contemporary web pages use many resources: HTML, style sheets, scripts, images and so on. In HTTP/1.x each of these resources must be requested explicitly. This can be a slow process. So the browser starts by getting the HTML, and then incrementally gets more resources as it parses and evaluates the page. Because the server must wait for the browser to make every request, the network is often idle and underused.
To improve latency, HTTP/2 introduced server push, which allows the server to push resources to the browser before the browser explicitly requests them. A server often knows that a page requires many additional resources and can start pushing those resources when it responds to the browser's first request. This allows the server to fully utilize a potentially idle network, improving page load times.
serverpush.svg.png
At the protocol layer, HTTP/2 server push is driven by push_promise frames. A PUSH_PROMISE describes a request, that is, server-side predictive browsing The server will issue the request immediately. As soon as the browser receives the PUSH_PROMISE, it immediately knows that the server is going to transfer this resource. If the browser subsequently discovers that it needs the resource, it will wait for the push to complete rather than sending a new request. This reduces the time the browser spends waiting for the network.
Server push in net/http package
go1.8 introduces support for push responses from http.Server. This feature is available if the running server is an HTTP/2 service and incoming connections use HTTP/2. In any HTTP handler, you can determine whether http.ResponseWriter supports server push by checking whether it implements the new http.Pusher interface.
For example, if the server knows that app.js will be requested to render the page, the handler can initiate a push if http.Pusher is available.
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { if pusher, ok := w.(http.Pusher); ok { // Push is supported. if err := pusher.Push("/app.js", nil); err != nil { log.Printf("Failed to push: %v", err) } } // ... })
I believe you have mastered the method after reading the above introduction. For more exciting information, please pay attention to the php Chinese website Other related articles!
Related reading:
What does the JS engine look like when running
How does native JS implement AJAX and JSONP
How to customize the console object during the use of JS
The above is the detailed content of About HTTP/2 server push. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The role of a DHCP relay is to forward received DHCP packets to another DHCP server on the network, even if the two servers are on different subnets. By using a DHCP relay, you can deploy a centralized DHCP server in the network center and use it to dynamically assign IP addresses to all network subnets/VLANs. Dnsmasq is a commonly used DNS and DHCP protocol server that can be configured as a DHCP relay server to help manage dynamic host configurations in the network. In this article, we will show you how to configure dnsmasq as a DHCP relay server. Content Topics: Network Topology Configuring Static IP Addresses on a DHCP Relay D on a Centralized DHCP Server

In network data transmission, IP proxy servers play an important role, helping users hide their real IP addresses, protect privacy, and improve access speeds. In this article, we will introduce the best practice guide on how to build an IP proxy server with PHP and provide specific code examples. What is an IP proxy server? An IP proxy server is an intermediate server located between the user and the target server. It acts as a transfer station between the user and the target server, forwarding the user's requests and responses. By using an IP proxy server

Understand the meaning of HTTP 301 status code: common application scenarios of web page redirection. With the rapid development of the Internet, people's requirements for web page interaction are becoming higher and higher. In the field of web design, web page redirection is a common and important technology, implemented through the HTTP 301 status code. This article will explore the meaning of HTTP 301 status code and common application scenarios in web page redirection. HTTP301 status code refers to permanent redirect (PermanentRedirect). When the server receives the client's

What should I do if I can’t enter the game when the epic server is offline? This problem must have been encountered by many friends. When this prompt appears, the genuine game cannot be started. This problem is usually caused by interference from the network and security software. So how should it be solved? The editor of this issue will explain I would like to share the solution with you, I hope today’s software tutorial can help you solve the problem. What to do if the epic server cannot enter the game when it is offline: 1. It may be interfered by security software. Close the game platform and security software and then restart. 2. The second is that the network fluctuates too much. Try restarting the router to see if it works. If the conditions are OK, you can try to use the 5g mobile network to operate. 3. Then there may be more

Business cards are a method that can be used to push friends in the software WeChat. Some users don’t know how to push friends’ business cards in WeChat. Just click on the friend’s personal page, select More to recommend them to friends and send them. This article is about WeChat push. The introduction of the friend’s business card method can tell you the specific content. The following is a detailed introduction, take a look! WeChat usage tutorial: How to push a friend’s business card on WeChat? Answer: Click on the friend’s personal page, select More to recommend them to friends and send them. Details: 1. Click on the friend you want to push a business card to. 2. Click the [More] option in the upper right corner. 3. Then click [Recommend TA to friends]. 4. Select the friend you want to send a business card to. 5. Click [Send].

How to install PHPFFmpeg extension on server? Installing the PHPFFmpeg extension on the server can help us process audio and video files in PHP projects and implement functions such as encoding, decoding, editing, and processing of audio and video files. This article will introduce how to install the PHPFFmpeg extension on the server, as well as specific code examples. First, we need to ensure that PHP and FFmpeg are installed on the server. If FFmpeg is not installed, you can follow the steps below to install FFmpe

Golang is an open source programming language developed by Google. It is efficient, fast and powerful and is widely used in cloud computing, network programming, big data processing and other fields. As a strongly typed, static language, Golang has many advantages when building server-side applications. This article will analyze the advantages and utility of Golang server in detail, and illustrate its power through specific code examples. 1. The high-performance Golang compiler can compile the code into local code

How to implement HTTP streaming in C++? Create an SSL stream socket using Boost.Asio and the asiohttps client library. Connect to the server and send an HTTP request. Receive HTTP response headers and print them. Receives the HTTP response body and prints it.
