@nora-soderlund/http-early-hints
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);