From edd5c1582b090aac85785a8d53bd88ca9b73a0a4 Mon Sep 17 00:00:00 2001 From: Unchained Date: Tue, 31 Mar 2026 20:08:56 +0200 Subject: [PATCH] feat(performance): add ISR and Cloudflare cache headers - Add revalidate=3600 to homepage and products page (1hr ISR) - Add middleware to set cache headers for HTML pages - Bypass cache for checkout and cart pages --- src/app/[locale]/page.tsx | 2 ++ src/app/[locale]/products/page.tsx | 2 ++ src/middleware.ts | 35 ++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 src/middleware.ts diff --git a/src/app/[locale]/page.tsx b/src/app/[locale]/page.tsx index b75da9a..7dc6ff0 100644 --- a/src/app/[locale]/page.tsx +++ b/src/app/[locale]/page.tsx @@ -16,6 +16,8 @@ import { getPageKeywords, getBrandKeywords } from "@/lib/seo/keywords"; import { Metadata } from "next"; import Image from "next/image"; +export const revalidate = 3600; + const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || "https://manoonoils.com"; export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }): Promise { diff --git a/src/app/[locale]/products/page.tsx b/src/app/[locale]/products/page.tsx index 4a0ea77..1604174 100644 --- a/src/app/[locale]/products/page.tsx +++ b/src/app/[locale]/products/page.tsx @@ -9,6 +9,8 @@ import { isValidLocale, DEFAULT_LOCALE, getSaleorLocale, type Locale } from "@/l import { getPageKeywords } from "@/lib/seo/keywords"; import { Metadata } from "next"; +export const revalidate = 3600; + const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || "https://manoonoils.com"; interface ProductsPageProps { diff --git a/src/middleware.ts b/src/middleware.ts new file mode 100644 index 0000000..d98321a --- /dev/null +++ b/src/middleware.ts @@ -0,0 +1,35 @@ +import { NextResponse } from "next/server"; +import type { NextRequest } from "next/server"; + +export function middleware(request: NextRequest) { + const response = NextResponse.next(); + + const url = request.nextUrl.pathname; + + if ( + url.startsWith("/sr") || + url.startsWith("/en") || + url.startsWith("/de") || + url.startsWith("/fr") || + url === "/" + ) { + if ( + !url.includes("/checkout") && + !url.includes("/cart") && + !url.includes("/api/") + ) { + response.headers.set( + "Cache-Control", + "public, max-age=3600, stale-while-revalidate=86400" + ); + } + } + + return response; +} + +export const config = { + matcher: [ + "/((?!_next/static|_next/image|favicon.ico|icon.png|robots.txt|sitemap.xml).*)", + ], +}; \ No newline at end of file