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

@@ -4,7 +4,7 @@ import { PUBLIC_LIST_AMOUNT } from '$env/static/public'
import { fetchAPI, photoFields } from '$utils/api'
export const load: PageServerLoad = async ({ params }) => {
export const load: PageServerLoad = async ({ params, setHeaders }) => {
try {
const { location: slug } = params
@@ -71,6 +71,8 @@ export const load: PageServerLoad = async ({ params }) => {
throw error(404, "This location is not available… yet!")
}
setHeaders({ 'Cache-Control': 'public, max-age=1, stale-while-revalidate=604799' })
return {
location: location[0],
photos,

View File

@@ -2,7 +2,7 @@ import { error } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'
import { fetchAPI } from '$utils/api'
export const load: PageServerLoad = async ({ params }) => {
export const load: PageServerLoad = async ({ params, setHeaders }) => {
try {
// Get the first photo ID
const firstPhoto = await fetchAPI(`query {
@@ -74,6 +74,8 @@ export const load: PageServerLoad = async ({ params }) => {
if (data) {
const currentIndex = data.photos.findIndex((photo: any) => photo.slug === params.photo)
setHeaders({ 'Cache-Control': 'public, max-age=1, stale-while-revalidate=604799' })
return {
photos: data.photos,
location: data.location[0],