Skip to content

Commit

Permalink
feat: add cache control headers
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromtec committed Jan 23, 2025
1 parent e5c22c2 commit 4142dc5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/core/src/pages/s.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function Page({ page: searchContentType, globalSections, searchTerm }: Props) {
const searchParams = useSearchParams({
sort: settings?.productGallery?.sortBySelection as SearchState['sort'],
})
console.log({ searchTerm })

const title = 'Search Results'
const { description, titleTemplate } = storeConfig.seo
const itemsPerPage = settings?.productGallery?.itemsPerPage ?? ITEMS_PER_PAGE
Expand Down Expand Up @@ -120,9 +120,10 @@ export const getServerSideProps: GetServerSideProps<
Record<string, string>,
Locator
> = async (context) => {
const { previewData, query } = context
const { previewData, query, res } = context

const searchTerm = (query.q as string)?.split('+').join(' ')

const searchTerm = query.q as string
const globalSections = await getGlobalSectionsData(previewData)

if (storeConfig.cms.data) {
Expand All @@ -147,6 +148,11 @@ export const getServerSideProps: GetServerSideProps<
contentType: 'search',
})

res.setHeader(
'Cache-Control',
'public, s-maxage=300, stale-while-revalidate=31536000'
) // 5 minutes of fresh content and 1 year of stale content

return {
props: {
page,
Expand Down

0 comments on commit 4142dc5

Please sign in to comment.