Cache-control

This commit is contained in:
Daniel Kluge 2022-11-03 15:12:03 +01:00
parent 652d84e296
commit f56a04b2e7
4 changed files with 11 additions and 3 deletions

View File

@ -21,6 +21,8 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
const contentHtml = await generateContent(contentEntry) as string; const contentHtml = await generateContent(contentEntry) as string;
const contentPrepared = prepareDOM(contentHtml); const contentPrepared = prepareDOM(contentHtml);
context.res.setHeader("Cache-Control", "public, s-maxage=3600, stale-while-revalidate=600");
return { return {
props: { props: {
content: { content: {

View File

@ -21,6 +21,8 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
const contentHtml = await generateContent(contentEntry, Number.parseInt(page)) as string; const contentHtml = await generateContent(contentEntry, Number.parseInt(page)) as string;
const contentPrepared = prepareDOM(contentHtml); const contentPrepared = prepareDOM(contentHtml);
context.res.setHeader("Cache-Control", "public, s-maxage=3600, stale-while-revalidate=600");
return { return {
props: { props: {
content: { content: {

View File

@ -22,6 +22,8 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
const contentHtml = await generateContent(contentEntry) as string; const contentHtml = await generateContent(contentEntry) as string;
const contentPrepared = prepareDOM(contentHtml); const contentPrepared = prepareDOM(contentHtml);
context.res.setHeader("Cache-Control", "public, s-maxage=3600, stale-while-revalidate=600");
return { return {
props: { props: {
content: { content: {

View File

@ -1,4 +1,4 @@
import type { NextPage } from "next"; import type { GetServerSideProps, NextPage } from "next";
import Link from "next/link"; import Link from "next/link";
import gen from "random-seed"; import gen from "random-seed";
import Layout from "../components/Blog/Layout"; import Layout from "../components/Blog/Layout";
@ -57,8 +57,10 @@ const Blog: NextPage<{ content: ContentList }> = ({content}) => {
}; };
export async function getServerSideProps() { export const getServerSideProps: GetServerSideProps = async ({ res }) => {
res.setHeader("Cache-Control", "public, s-maxage=3600, stale-while-revalidate=600");
return { props: { content: await getContentList() } }; return { props: { content: await getContentList() } };
} };
export default Blog; export default Blog;