@nora-soderlund/http-early-hints

1.0.2 • Public • Published

@nora-soderlund/http-early-hints

npm (scoped) npm bundle size (minified)

Sends a 103 Early Hints header to supported clients.

Install

$ npm install @nora-soderlund/http-early-hints

Usage

const fs = require("fs");

const http = require("http");
const httpServer = http.createServer();
const { httpWriteEarlyHints } = require("@nora-soderlund/http-early-hints");

httpServer.on("request", (request, response) => {
    if(request.url == "/index.html") {
        console.log(`103 Early Hints for ${request.url}`);

        httpWriteEarlyHints(request, response, [
            "</main.css>; rel=preload; as=style"
        ]);

        // process the response

        console.log(`200 OK for ${request.url}`);

        // include the Link headers in the final header for backwards compability

        response.writeHead(200, "OK", {
            //"Content-Type": "text/html; charset=UTF-8",
            "Link": hints
        });

        // response.end();
    }
});

httpServer.listen(80);

Readme

Keywords

none

Package Sidebar

Install

npm i @nora-soderlund/http-early-hints

Weekly Downloads

1

Version

1.0.2

License

ISC

Unpacked Size

33.6 kB

Total Files

12

Last publish

Collaborators

  • nora-soderlund