Skip to content

Commit

Permalink
Add HTTP/2 Server Push Link header
Browse files Browse the repository at this point in the history
  • Loading branch information
Plopix committed May 15, 2022
1 parent 15d18e6 commit 60859d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
- pcattori
- phishy
- plastic041
- plopix
- princerajroy
- prvnbist
- ptitFicus
Expand Down
11 changes: 11 additions & 0 deletions templates/remix/app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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("<!DOCTYPE html>" + markup, {
status: responseStatusCode,
headers: responseHeaders,
Expand Down

0 comments on commit 60859d5

Please sign in to comment.