diff --git a/contributors.yml b/contributors.yml index 8b76fad011b..5ec94c4ffa2 100644 --- a/contributors.yml +++ b/contributors.yml @@ -386,6 +386,7 @@ - phishy - plastic041 - plondon +- plopix - pmbanugo - princerajroy - prvnbist diff --git a/templates/remix/app/entry.server.tsx b/templates/remix/app/entry.server.tsx index c78d5047bc9..e4a279799ff 100644 --- a/templates/remix/app/entry.server.tsx +++ b/templates/remix/app/entry.server.tsx @@ -15,17 +15,17 @@ export default function handleRequest( ) { return isbot(request.headers.get("user-agent")) ? handleBotRequest( - request, - responseStatusCode, - responseHeaders, - remixContext - ) + request, + responseStatusCode, + responseHeaders, + remixContext + ) : handleBrowserRequest( - request, - responseStatusCode, - responseHeaders, - remixContext - ); + request, + responseStatusCode, + responseHeaders, + remixContext + ); } function handleBotRequest( @@ -46,6 +46,14 @@ function handleBotRequest( const body = new PassThrough(); responseHeaders.set("Content-Type", "text/html"); + responseHeaders.set( + "Link", + httpPushLinks(remixContext) + .map((link: string) => `<${link}>; rel=preload; as=script; crossorigin=anonymous`) + .concat(responseHeaders.get("Link") as string) + .filter(Boolean) + .join(",") + ); resolve( new Response(body, { @@ -88,6 +96,13 @@ function handleBrowserRequest( const body = new PassThrough(); responseHeaders.set("Content-Type", "text/html"); + responseHeaders.set( + "Link", + httpPushLinks(remixContext).map((link: string) => `<${link}>; rel=preload; as=script; crossorigin=anonymous`) + .concat(responseHeaders.get("Link") as string) + .filter(Boolean) + .join(",") + ); resolve( new Response(body, { @@ -111,3 +126,17 @@ function handleBrowserRequest( setTimeout(abort, ABORT_DELAY); }); } + + +function httpPushLinks(remixContext: EntryContext) { + console.log([ + remixContext.manifest.url, + remixContext.manifest.entry.module, + ...remixContext.manifest.entry.imports, + ]); + return [ + remixContext.manifest.url, + remixContext.manifest.entry.module, + ...remixContext.manifest.entry.imports, + ]; +}