diff --git a/templates/remix/app/entry.server.tsx b/templates/remix/app/entry.server.tsx index aa0aa0978b1..a123baefb6f 100644 --- a/templates/remix/app/entry.server.tsx +++ b/templates/remix/app/entry.server.tsx @@ -14,6 +14,17 @@ export default function handleRequest( responseHeaders.set("Content-Type", "text/html"); + // Add Link header for HTTP/2 Server Push + let http2PushLinksHeaders = remixContext.matches.reduce((acc: string[], { route: { module, imports } }) => { + acc.push(module); + if (imports) { + acc.push(...imports); + } + return acc; + }, []); + http2PushLinksHeaders.push(...[remixContext.manifest.url, remixContext.manifest.entry.module, ...remixContext.manifest.entry.imports]) + responseHeaders.set("Link", (responseHeaders.has("Link") ? responseHeaders.get("Link") + "," : '') + http2PushLinksHeaders.map((link: string) => `<${link}>; rel=preload; as=script`).join(",")); + return new Response("" + markup, { status: responseStatusCode, headers: responseHeaders,