Skip to content

Commit 128c161

Browse files
committed
perf: add long-term caching for note and user images
1 parent 40750b1 commit 128c161

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

app/routes/resources+/note-images.$imageId.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,13 @@ export async function loader({ params }: Route.LoaderArgs) {
1212
invariantResponse(noteImage, 'Note image not found', { status: 404 })
1313

1414
const { url, headers } = getSignedGetRequestInfo(noteImage.storageKey)
15-
return fetch(url, { headers })
15+
const response = await fetch(url, { headers })
16+
17+
const cacheHeaders = new Headers(response.headers)
18+
cacheHeaders.set('Cache-Control', 'public, max-age=31536000, immutable')
19+
20+
return new Response(response.body, {
21+
status: response.status,
22+
headers: cacheHeaders,
23+
})
1624
}

app/routes/resources+/user-images.$imageId.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ export async function loader({ params }: Route.LoaderArgs) {
1010
select: { storageKey: true },
1111
})
1212
invariantResponse(userImage, 'User image not found', { status: 404 })
13+
1314
const { url, headers } = getSignedGetRequestInfo(userImage.storageKey)
14-
return fetch(url, { headers })
15+
const response = await fetch(url, { headers })
16+
17+
const cacheHeaders = new Headers(response.headers)
18+
cacheHeaders.set('Cache-Control', 'public, max-age=31536000, immutable')
19+
20+
return new Response(response.body, {
21+
status: response.status,
22+
headers: cacheHeaders,
23+
})
1524
}

0 commit comments

Comments
 (0)