Use page specific stale-while-revalidate Cache-Control headers
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user