1.0.2 • Published 2 years ago

@nora-soderlund/http-early-hints v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

@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);