Code Monkey home page Code Monkey logo

pusher's Introduction

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

pusher's People

Contributors

romainmenke avatar

Watchers

James Cloos avatar Samarjeet Dubey avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.