HTTP/2 Server Push — ELI5
Imagine you sit down at a restaurant and order a burger. A good waiter knows you’re going to need ketchup, napkins, and a drink refill — so they bring them along with your burger without waiting for you to ask. That saves you three extra trips of flagging them down.
HTTP/2 Server Push works the same way. When your browser asks a Python server for a web page, the server already knows the page needs a CSS file, a JavaScript file, and a logo image. Instead of waiting for the browser to read the page, discover those files, and make three separate requests, the server pushes them all at once alongside the original page.
With the older HTTP/1.1, the browser would:
- Ask for the page
- Get the page back
- Read it and find out it needs style.css
- Ask for style.css
- Get style.css and find out it needs script.js
- Ask for script.js…
Each round trip takes time, especially on slow connections. Server push cuts out steps 3-4 and 5-6.
However, there’s a catch: browsers have been getting smarter at predicting what they’ll need, and server push sometimes sends files the browser already has cached. That’s like the waiter bringing ketchup when there’s already a full bottle on the table. Because of this, Chrome actually removed support for server push in 2022, and most modern web development uses other techniques instead.
One thing to remember: Server push was a clever idea to reduce wait times by sending resources before the browser asks, but smarter caching and new techniques like early hints have largely replaced it.
See Also
- Python Aiohttp Client Understand Aiohttp Client through a practical analogy so your Python decisions become faster and clearer.
- Python Api Client Design Why building your own API client in Python is like creating a TV remote that only has the buttons you actually need.
- Python Api Documentation Swagger Swagger turns your Python API into an interactive playground where anyone can click buttons to try it out — no coding required.
- Python Api Mocking Responses Why testing with fake API responses is like rehearsing a play with stand-ins before the real actors show up.
- Python Api Pagination Clients Why APIs send data in pages, and how Python handles it — like reading a book one chapter at a time instead of swallowing the whole thing.