Skip to content

Commit

Permalink
Add SSR caching (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashachabin committed Dec 21, 2023
1 parent 78e3c2f commit c788f7c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export default function Home({ manualsPreview }) {
return <MainPage manualsPreview={manualsPreview} />
}

export async function getServerSideProps() {
export async function getServerSideProps({ res }) {
setCacheHeaders(res)

const tree = await loadTree()

return {
Expand Down
4 changes: 3 additions & 1 deletion pages/manuals/[[...pageUrl]].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ function GetPage({
)
}

export async function getServerSideProps({ params: { pageUrl } }) {
export async function getServerSideProps({ params: { pageUrl }, res }) {
setCacheHeaders(res)

const tree = await loadTree()
const children = tree?.children
const manualPath = pageUrl
Expand Down
3 changes: 3 additions & 0 deletions utils/setCacheHeaders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function setCacheHeaders(res) {
res.setHeader('Cache-Control', 'public, s-maxage=900, stale-while-revalidate=900')
}

0 comments on commit c788f7c

Please sign in to comment.