mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-21 01:21:16 -04:00
lengthen cache-control headers
This commit is contained in:
@@ -1 +1 @@
|
|||||||
16.14.2
|
16.15.0
|
||||||
|
@@ -66,7 +66,9 @@ const CopyButton = forwardRef(function CopyButton(
|
|||||||
}, timeout);
|
}, timeout);
|
||||||
|
|
||||||
// cancel timeout to avoid memory leaks if unmounted in the middle of this
|
// cancel timeout to avoid memory leaks if unmounted in the middle of this
|
||||||
return () => clearTimeout(reset);
|
return () => {
|
||||||
|
clearTimeout(reset);
|
||||||
|
};
|
||||||
}, [timeout, copied]);
|
}, [timeout, copied]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@@ -10,10 +10,17 @@ export type HitCounterProps = {
|
|||||||
|
|
||||||
const HitCounter = ({ slug, className }: HitCounterProps) => {
|
const HitCounter = ({ slug, className }: HitCounterProps) => {
|
||||||
// start fetching repos from API immediately
|
// start fetching repos from API immediately
|
||||||
const { data, error } = useSWR(`/api/hits/?slug=${encodeURIComponent(slug)}`, fetcher, {
|
const { data, error } = useSWR(
|
||||||
|
`/api/hits/?${new URLSearchParams({
|
||||||
|
slug,
|
||||||
|
})}`,
|
||||||
|
fetcher,
|
||||||
|
{
|
||||||
// avoid double (or more) counting views
|
// avoid double (or more) counting views
|
||||||
revalidateOnFocus: false,
|
revalidateOnFocus: false,
|
||||||
});
|
revalidateOnReconnect: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// show spinning loading indicator if data isn't fetched yet
|
// show spinning loading indicator if data isn't fetched yet
|
||||||
if (!data) {
|
if (!data) {
|
||||||
|
@@ -9,7 +9,7 @@ import type { ParsedUrlQuery } from "querystring";
|
|||||||
|
|
||||||
export type BuildFeedOptions = {
|
export type BuildFeedOptions = {
|
||||||
type?: "rss" | "atom" | "json"; // defaults to rss
|
type?: "rss" | "atom" | "json"; // defaults to rss
|
||||||
edgeCacheAge?: number; // defaults to 3600 (one hour)
|
edgeCacheAge?: number; // in seconds, defaults to 43200 (12 hours)
|
||||||
};
|
};
|
||||||
|
|
||||||
// handles literally *everything* about building the server-side rss/atom feeds and writing the response.
|
// handles literally *everything* about building the server-side rss/atom feeds and writing the response.
|
||||||
@@ -59,8 +59,8 @@ export const buildFeed = async (
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// cache on edge for one hour by default
|
// cache on edge for 12 hours by default
|
||||||
res.setHeader("cache-control", `s-maxage=${options.edgeCacheAge ?? 3600}, stale-while-revalidate`);
|
res.setHeader("cache-control", `s-maxage=${options.edgeCacheAge ?? 43200}, stale-while-revalidate=3600`);
|
||||||
|
|
||||||
// generates RSS by default
|
// generates RSS by default
|
||||||
if (options.type === "atom") {
|
if (options.type === "atom") {
|
||||||
|
@@ -115,7 +115,7 @@ export const getAllNotes = async (): Promise<NoteFrontMatter[]> => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// sort the results by date
|
// sort the results by date
|
||||||
const sorted = data.sort((note1, note2) => (note1.date > note2.date ? -1 : 1));
|
data.sort((note1, note2) => (note1.date > note2.date ? -1 : 1));
|
||||||
|
|
||||||
return sorted;
|
return data;
|
||||||
};
|
};
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fontsource/comic-neue": "4.5.8",
|
"@fontsource/comic-neue": "4.5.8",
|
||||||
"@fontsource/inter": "4.5.9",
|
"@fontsource/inter": "4.5.10",
|
||||||
"@fontsource/roboto-mono": "4.5.7",
|
"@fontsource/roboto-mono": "4.5.7",
|
||||||
"@giscus/react": "^2.0.3",
|
"@giscus/react": "^2.0.3",
|
||||||
"@hcaptcha/react-hcaptcha": "^1.3.0",
|
"@hcaptcha/react-hcaptcha": "^1.3.0",
|
||||||
@@ -110,7 +110,7 @@
|
|||||||
},
|
},
|
||||||
"packageManager": "yarn@1.22.18",
|
"packageManager": "yarn@1.22.18",
|
||||||
"volta": {
|
"volta": {
|
||||||
"node": "16.14.2",
|
"node": "16.15.0",
|
||||||
"yarn": "1.22.18"
|
"yarn": "1.22.18"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -46,7 +46,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
const siteStats = await getSiteStats(client);
|
const siteStats = await getSiteStats(client);
|
||||||
|
|
||||||
// let Vercel edge cache results for 15 mins
|
// let Vercel edge cache results for 15 mins
|
||||||
res.setHeader("Cache-Control", "s-maxage=900, stale-while-revalidate");
|
res.setHeader("Cache-Control", "s-maxage=900, stale-while-revalidate=60");
|
||||||
|
|
||||||
// return in JSON format
|
// return in JSON format
|
||||||
return res.status(200).json(siteStats);
|
return res.status(200).json(siteStats);
|
||||||
|
@@ -41,8 +41,8 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
|||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/Manifest#deploying_a_manifest
|
// https://developer.mozilla.org/en-US/docs/Web/Manifest#deploying_a_manifest
|
||||||
res.setHeader("content-type", "application/manifest+json; charset=utf-8");
|
res.setHeader("content-type", "application/manifest+json; charset=utf-8");
|
||||||
// cache on edge for one day
|
// cache on edge for one week
|
||||||
res.setHeader("cache-control", "s-maxage=604800, stale-while-revalidate");
|
res.setHeader("cache-control", "s-maxage=604800, stale-while-revalidate=86400");
|
||||||
res.write(JSON.stringify(manifest));
|
res.write(JSON.stringify(manifest));
|
||||||
res.end();
|
res.end();
|
||||||
|
|
||||||
|
@@ -47,7 +47,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
|||||||
|
|
||||||
// cache on edge for 12 hours
|
// cache on edge for 12 hours
|
||||||
const { res } = context;
|
const { res } = context;
|
||||||
res.setHeader("cache-control", "s-maxage=43200, stale-while-revalidate");
|
res.setHeader("cache-control", "s-maxage=43200, stale-while-revalidate=3600");
|
||||||
|
|
||||||
// next-sitemap takes care of the rest of the response for us
|
// next-sitemap takes care of the rest of the response for us
|
||||||
return getServerSideSitemap(context, pages);
|
return getServerSideSitemap(context, pages);
|
||||||
|
20
yarn.lock
20
yarn.lock
@@ -1048,10 +1048,10 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@fontsource/comic-neue/-/comic-neue-4.5.8.tgz#269237c1b11d16efa1729a45cdd317799156204d"
|
resolved "https://registry.yarnpkg.com/@fontsource/comic-neue/-/comic-neue-4.5.8.tgz#269237c1b11d16efa1729a45cdd317799156204d"
|
||||||
integrity sha512-m4Y/o/L8mzAuiWXBHisijMmCHDpHXFMxRyFQ6mDeBlOwlyUU7PB2XdrV6utR/1Y0wPjxa8AZKEYPMy1tBXDURA==
|
integrity sha512-m4Y/o/L8mzAuiWXBHisijMmCHDpHXFMxRyFQ6mDeBlOwlyUU7PB2XdrV6utR/1Y0wPjxa8AZKEYPMy1tBXDURA==
|
||||||
|
|
||||||
"@fontsource/inter@4.5.9":
|
"@fontsource/inter@4.5.10":
|
||||||
version "4.5.9"
|
version "4.5.10"
|
||||||
resolved "https://registry.yarnpkg.com/@fontsource/inter/-/inter-4.5.9.tgz#ae3d49935172684c39a75f1ec9d405d015ac5959"
|
resolved "https://registry.yarnpkg.com/@fontsource/inter/-/inter-4.5.10.tgz#c4e6839197dc4c77842eae9475ff0e036ff87fc9"
|
||||||
integrity sha512-EwLZGA8De5r/EFokSNU+JKZRcpC9SlqBCg/2XhNzt9QWS3aPR6Xdo1oHJ8LhhGkgOReRo1sgpIrdcz9UMtUcOQ==
|
integrity sha512-YOt2/K8yo25MVBjrTImHxVimmyZEt0GcrWp2w7O29sdFX9SJqbGlOqjFJ1wI5yBbP6AmTeimyPE0UC/jjFRoIA==
|
||||||
|
|
||||||
"@fontsource/roboto-mono@4.5.7":
|
"@fontsource/roboto-mono@4.5.7":
|
||||||
version "4.5.7"
|
version "4.5.7"
|
||||||
@@ -1643,9 +1643,9 @@
|
|||||||
integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==
|
integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==
|
||||||
|
|
||||||
"@types/node@*":
|
"@types/node@*":
|
||||||
version "17.0.30"
|
version "17.0.31"
|
||||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.30.tgz#2c6e8512acac70815e8176aa30c38025067880ef"
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.31.tgz#a5bb84ecfa27eec5e1c802c6bbf8139bdb163a5d"
|
||||||
integrity sha512-oNBIZjIqyHYP8VCNAV9uEytXVeXG2oR0w9lgAXro20eugRQfY002qr3CUl6BAe+Yf/z3CRjPdz27Pu6WWtuSRw==
|
integrity sha512-AR0x5HbXGqkEx9CadRH3EBYx/VkiUgZIhP4wvPn/+5KIsgpNoyFaRlVe0Zlx9gRtg8fA06a9tskE2MSN7TcG4Q==
|
||||||
|
|
||||||
"@types/parse-json@^4.0.0":
|
"@types/parse-json@^4.0.0":
|
||||||
version "4.0.0"
|
version "4.0.0"
|
||||||
@@ -2150,9 +2150,9 @@ camelcase@^6.2.0:
|
|||||||
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==
|
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==
|
||||||
|
|
||||||
caniuse-lite@^1.0.30001283, caniuse-lite@^1.0.30001332:
|
caniuse-lite@^1.0.30001283, caniuse-lite@^1.0.30001332:
|
||||||
version "1.0.30001334"
|
version "1.0.30001335"
|
||||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001334.tgz#892e9965b35285033fc2b8a8eff499fe02f13d8b"
|
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001335.tgz#899254a0b70579e5a957c32dced79f0727c61f2a"
|
||||||
integrity sha512-kbaCEBRRVSoeNs74sCuq92MJyGrMtjWVfhltoHUCW4t4pXFvGjUBrfo47weBRViHkiV3eBYyIsfl956NtHGazw==
|
integrity sha512-ddP1Tgm7z2iIxu6QTtbZUv6HJxSaV/PZeSrWFZtbY4JZ69tOeNhBCl3HyRQgeNZKE5AOn1kpV7fhljigy0Ty3w==
|
||||||
|
|
||||||
ccount@^1.0.0:
|
ccount@^1.0.0:
|
||||||
version "1.1.0"
|
version "1.1.0"
|
||||||
|
Reference in New Issue
Block a user