Course contentsShow
← Web Development
Lesson 2121 of 2,98239. Network PerformanceFree lesson

HTTP/2 Server Push

Explore how servers can proactively send resources to the client before they're requested.

What You'll Learn

You'll learn how HTTP/2 Server Push lets servers proactively send resources to the client before the browser even asks for them, potentially eliminating round-trip delays.

The Core Idea

Traditionally, web resource loading follows a request-response cycle: the browser requests HTML, parses it, discovers CSS/JS references, then requests those too. Each discovery adds network round trips.

HTTP/2 Server Push breaks this pattern. When the server sends an HTML file, it can also push related resources (like CSS or JavaScript) along with it—before the browser has parsed the HTML and figured out it needs them.

Think of it like a restaurant: normally you order appetizers (HTML), the waiter brings them, you read the menu, then order the main course (CSS/JS). With Server Push, the chef anticipates what you'll want and sends both together from the start.

How It Works

When configured, the server includes a Link header with rel=preload or uses HTTP/2's PUSH_PROMISE frame:

Link: </styles.css>; rel=preload; as=style
Link: </app.js>; rel=preload; as=script

The server then immediately sends these resources through the multiplexed HTTP/2 connection (covered in your previous lesson), without waiting for browser requests.

The Catch

Server Push sounds ideal but has pitfalls:

  • Cache Ignorance: The server doesn't know what's already in the browser cache, potentially pushing resources the client already has
  • Bandwidth Waste: Over-pushing can actually slow down initial render by delaying more critical resources
  • Complexity: Requires careful configuration to push only what's beneficial

Many developers now prefer <link rel=preload> headers, which hint to the browser without forcing pushes, letting the browser make smarter decisions based on cache state.

Key Takeaway:
HTTP/2 Server Push allows servers to anticipate and send resources before requests arrive, but requires careful implementation to avoid pushing cached or unnecessary resources that waste bandwidth.