Created
March 30, 2024 18:24
-
-
Save carvalhochris/a4ecd589731f40f3e1b640b71b0b5582 to your computer and use it in GitHub Desktop.
add cache control headers to dynamic page (Next.js pages router)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const getServerSideProps = (async (context) => { | |
| const id = context.query.id; | |
| const res = await fetch(`https://api.../posts/${id}/`, { | |
| ... | |
| }); | |
| context.res.setHeader( | |
| "Cache-Control", | |
| "public, s-maxage=604800, stale-while-revalidate=59" | |
| ); | |
| const post = await res.json(); | |
| return { props: { post } }; | |
| }) satisfies GetServerSideProps<{ | |
| post: Post; | |
| }>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment