on master help sign in
group, id: aggressively cache

Pages are considered stale after 1 hour, but for a week afterward will be served stale + refetched in background when requested.

commit89d422858c18cc693ad0ed68679fb0b21f803afe authorMatilde Park <matilde.park@urbit.org> dateMon 25 Apr 2022, 10:27 (5 years ago) parent671bbe3
2 files changed+12−2
pages/group/[[...group]].js+6−1 pages/id/[id].js+6−1
pages/group/[[...group]].js+6−1
@@ -137,7 +137,12 @@ const GroupPage = ({ data, markdown, params }) => {
137137 );
138138};
139139
140−export const getServerSideProps = async ({ params }) => {
140+export const getServerSideProps = async ({ params, res }) => {
141+ res.setHeader(
142+ "Cache-Control",
143+ "public, s-maxage=3600, stale-while-revalidate=604800"
144+ );
145+
141146 let { data, content } = getPage(
142147 join(process.cwd(), "content/group", params.group?.join("/") || "/")
143148 ) || { data: {}, content: "" };
pages/id/[id].js+6−1
@@ -176,7 +176,12 @@ function deSig(string) {
176176 return string.startsWith("~") ? string.substring(1) : string;
177177}
178178
179−export const getServerSideProps = async ({ params }) => {
179+export const getServerSideProps = async ({ params, res }) => {
180+ res.setHeader(
181+ "Cache-Control",
182+ "public, s-maxage=3600, stale-while-revalidate=604800"
183+ );
184+
180185 let { data, content } = getPage(
181186 join(process.cwd(), "content/id/", params.id.slice(1))
182187 ) || { data: {}, content: "" };