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 Jun 16, 2022
1 parent a114c40 commit 59a4338
Show file tree
Hide file tree
Showing 2 changed files with 18 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
17 changes: 17 additions & 0 deletions templates/remix/app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ 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",
http2PushLinksHeaders
.map((link: string) => `<${link}>; rel=preload; as=script; crossorigin=anonymous`)
.concat(responseHeaders.get("Link") as string)
.filter(Boolean)
.join(",")
);
return new Response("<!DOCTYPE html>" + markup, {
status: responseStatusCode,
headers: responseHeaders,
Expand Down

0 comments on commit 59a4338

Please sign in to comment.