Skip to content

HTTP/2

Overview

Upgrading to HTTP/2 is largely transparent. It requires:

HTTP Push

There is a feature called HTTP/2 server push which allows the server to notify the client of urls required by the document being served before the client has received the document.

This can be implemented in the following manner:

async def test_page(request: HttpRequest) -> HttpResponse:
    html = """
<!DOCTYPE html>
<html>
    <head>
    <meta charset="utf-8">
    <title>Example 1</title>
    <script src="/clickHandler.js"></script>
    </head>
    <body>
    <h1>Example 1</h1>
    <button type="button" onclick="handleClick('here')">
        Click me
    </button>
    <p id="here" />
    </body>
</html>

"""
    pushes = [
        ('/clickhandler.js', [(b'accept', b'text/javascript')])
    ]
    return HttpResponse(200, [(b'content-type', b'text/html')], text_writer(html), pushes)