-
Hello! How does one setup const markup = renderToString(
<RemixServer context={remixContext} url={request.url} />
);
headers.set("Content-Type", "text/html");
headers.set("ETag", etag(markup)); Now I don't know how to operate with the new |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
With streaming, you no longer have the entire markup before sending the Response to the client. If you want to use Something like this: // routes/blog.$.tsx
// return the Etag headers for full document requests as well
export const headers: HeadersFunction = ({ loaderHeaders }) => loaderHeaders
export async function loader({ request, params }: LoaderFunctionArgs) => {
let slug = params['*']
const post = await getPost(slug)
if (!post) {
throw new Response('Not Found', { status: 404 })
}
const weakHash = generateWeakHash(JSON.stringify(post))
const etag = request.headers.get('If-None-Match')
if (etag === weakHash) {
return new Response('Not Modified', { status: 304 })
}
return json({ post }, { headers: { 'Etag': weakHash } })
} |
Beta Was this translation helpful? Give feedback.
-
With the
Based on @kiliman example, replacing
This would result in a TypeScript error in the component where it uses |
Beta Was this translation helpful? Give feedback.
With streaming, you no longer have the entire markup before sending the Response to the client.
If you want to use
Etag
, then it's best to generate that based on your content rather than the resulting HTML.Something like this: