"use strict"; function handleRequest(request, response) { let qs = new URLSearchParams(request.queryString); let asset = qs.get("as"); let hinted = qs.get("hinted") === "1"; let httpCode = qs.get("code"); let uuid = qs.get("uuid"); let cached = qs.get("cached") === "1"; let url = `early_hint_asset.sjs?as=${asset}${uuid ? `&uuid=${uuid}` : ""}${ cached ? "&cached=1" : "" }`; // write to raw socket response.seizePower(); let link = ""; if (hinted) { response.write("HTTP/1.1 103 Early Hint\r\n"); if (asset === "fetch" || asset === "font") { // fetch and font has to specify the crossorigin attribute // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-as link = `Link: <${url}>; rel=preload; as=${asset}; crossorigin=anonymous\r\n`; response.write(link); } else if (asset === "module") { // module preloads are handled differently link = `Link: <${url}>; rel=modulepreload\r\n`; response.write(link); } else { link = `Link: <${url}>; rel=preload; as=${asset}\r\n`; response.write(link); } response.write("\r\n"); } let body = ""; if (asset === "image") { body = `
`; } else if (asset === "style") { body = `