Skip to content

Latest commit

 

History

History
53 lines (36 loc) · 2.72 KB

README.md

File metadata and controls

53 lines (36 loc) · 2.72 KB

Build Status Go Report Card codecov GoDoc

H2 Push Handlers

pusher is a collection of http.Handler's to easily enable HTTP2 Push.

  • link : a H2 Push handler based on Link headers.
  • casper : CASPer handler.
  • rules : Simple rules to generate Link headers or pushes.
  • parser : html body parser -> generates Push Frames / Link Headers for you.

Checkout the sub-packages for more details.


You probably already saw this code snippet from the go blog :

    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)
            }
        }
        // ...
    })

But obviously you don't want to hard code pushes for all your assets, especially in case of a proxy. That is where these handlers come in. Just choose the right one for the job.

Proxy Server

If you run a proxy server and want to enable H2 Push for all requests coming through, you implement the link pkg Handler and add Link headers on the source server. This approach is based on how Cloudflare enables H2 Push.

Client Side Rendered

Client Side Rendered websites often have known critical assets like the js bundle. In this case it makes sense to have a couple of rules for which assets to push for a certain path. This is what the rules pkg does. It adds Link headers or sends Pushes depending on your setup based on simple rules.

Server Side Rendered

A Server Side Rendered website with a CMS doesn't have known critical assets at deploy time. The parser pkg reads the first 1024 bytes from every html response and adds Link headers or sends Pushes depending on your setup.


The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)