[RFD] Define preload links based on loader data #6977
Replies: 2 comments 1 reply
-
Potentially related to #2905. |
Beta Was this translation helpful? Give feedback.
-
With v2 MetaFunction you can return link tags, and because MetaFunction receives the loader data you can render link tags based on that export async function loader({ request }: DataFunctionArgs) {
return json({ avatar: await getUserAvatar(request) })
}
export let meta: V2_MetaFunction<typeof loader> = ({ data }) => {
if (!data) return [];
return [
{ tagName: "link", rel: "preload", href: data.avatar, as: "image" }
]
} Note that if you also use In case you want to suggest passing |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Similar to how the
meta
function is passed your loader's data, it would be nice to be able to do something like this withlinks
:This has some benefits over simply inlining the
<link rel='preload'>
alongside the image (like Next.js does), mainly that Remix now knows about that preload and can preload it when I request to preload the user's page:Note that this proposal comes without me actually looking into Remix's source code at all (I don't know how hard this would be or if it is even possible). But I think this would be really cool to have for free from Remix.
Beta Was this translation helpful? Give feedback.
All reactions