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 17, 2022
1 parent a114c40 commit 91a17aa
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 @@ -259,6 +259,7 @@
- penspinner
- 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
.flatMap(({ route: { module, imports } }) => [module, ...(imports || [])])
.filter(Boolean)
.concat([
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 91a17aa

Please sign in to comment.