Use page specific stale-while-revalidate Cache-Control headers

This commit is contained in:
2022-09-20 00:20:18 +02:00
parent 39fc74d8e9
commit 5545871c85
12 changed files with 57 additions and 29 deletions

View File

@@ -3,7 +3,7 @@ import type { PageServerLoad } from './$types'
import { fetchAPI } from '$utils/api'
import { getRandomItems } from '$utils/functions'
export const load: PageServerLoad = async () => {
export const load: PageServerLoad = async ({ setHeaders }) => {
try {
// Get total of published photos
const totalRes = await fetchAPI(`query {
@@ -43,6 +43,8 @@ export const load: PageServerLoad = async () => {
const { data: { photo: photos }} = photosRes
if (photos) {
setHeaders({ 'Cache-Control': 'public, max-age=1, stale-while-revalidate=599' })
return {
photos,
}