Skip to content

Commit

Permalink
chore: update default and conf cache control to be SWR for 1 day (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-ebey authored Apr 4, 2024
1 parent 5ad0a6d commit 107b271
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
9 changes: 2 additions & 7 deletions app/lib/http.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@ import { redirect } from "@remix-run/node";
import redirectsFileContents from "../../_redirects?raw";

export const CACHE_CONTROL = {
/**
* Add 5 minutes cache control to documents and json requests to speed up the
* back button
*/
DEFAULT: "max-age=300",
/**
* Keep it in the browser (and CDN) for 5 minutes so when they click
* back/forward/etc. it's super fast. SWR for 1 week on CDN so it stays fast,
* but people get typos/fixes and stuff too.
*/
doc: "max-age=300, stale-while-revalidate=604800",
DEFAULT: "max-age=300, stale-while-revalidate=604800",
/**
* Keep it in the browser (and CDN) for 1 day, we won't be updating these as
* often until the conf is a bit closer, and we can prevent over-fetching from
* Sessionize which is pretty slow.
*/
conf: `max-age=${60 * 60 * 24}`,
conf: `max-age=${60 * 60 * 24}, stale-while-revalidate=604800`,
};

export function requirePost(request: Request) {
Expand Down
2 changes: 1 addition & 1 deletion app/routes/docs.$lang.$ref.$.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
if (!doc) throw null;
return json(
{ doc, siteUrl, ogImageUrl },
{ headers: { "Cache-Control": CACHE_CONTROL.doc } },
{ headers: { "Cache-Control": CACHE_CONTROL.DEFAULT } },
);
} catch (_) {
if (params.ref === "main" && params["*"]) {
Expand Down
2 changes: 1 addition & 1 deletion app/routes/docs.$lang.$ref.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {

export const headers: HeadersFunction = () => {
return {
"Cache-Control": CACHE_CONTROL.doc,
"Cache-Control": CACHE_CONTROL.DEFAULT,
Vary: "Cookie",
};
};
Expand Down

0 comments on commit 107b271

Please sign in to comment.