fix(cache): add aggressive no-store middleware, CSP updates, and client-side service worker & cache purge

This commit is contained in:
2026-11-17 11:00:09 +05:30
parent 28dd3beb90
commit d49bd5c721
6 changed files with 95 additions and 5 deletions
+3
View File
@@ -31,6 +31,9 @@ export async function generateMetadata(): Promise<Metadata> {
};
}
export const dynamic = 'force-dynamic';
export const revalidate = 0;
export default function AppsIndexPage() {
const page = getPageConfig('apps');
if (!page) notFound();
+39
View File
@@ -169,6 +169,45 @@ export default function RootLayout({
return (
<html lang="en" className={`${poppinsFont.variable} ${interFont.variable} ${monoFont.variable} font-sans`}>
<head>
<meta httpEquiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta httpEquiv="Pragma" content="no-cache" />
<meta httpEquiv="Expires" content="0" />
<script
dangerouslySetInnerHTML={{
__html: `
(function() {
try {
// 1. Unregister any stale Service Workers on client devices
if ('serviceWorker' in navigator) {
navigator.serviceWorker.getRegistrations().then(function(registrations) {
for (var i = 0; i < registrations.length; i++) {
registrations[i].unregister();
}
});
}
// 2. Clear stale Cache Storage API entries
if ('caches' in window) {
caches.keys().then(function(keys) {
for (var i = 0; i < keys.length; i++) {
caches.delete(keys[i]);
}
});
}
// 3. Automated cache-bust verification
var BUILD_TAG = '20261117_sfpro_v2';
var cachedTag = localStorage.getItem('__cre_build_tag');
if (cachedTag !== BUILD_TAG) {
localStorage.setItem('__cre_build_tag', BUILD_TAG);
if (cachedTag !== null && window.location.search.indexOf('v=') === -1) {
// Perform clean cache-busting reload once for returning visitors
window.location.replace(window.location.pathname + (window.location.search ? window.location.search + '&' : '?') + 'v=' + Date.now());
}
}
} catch(e) {}
})();
`,
}}
/>
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(organizationJsonLd) }}
+3
View File
@@ -45,6 +45,9 @@ export async function generateMetadata(): Promise<Metadata> {
};
}
export const dynamic = 'force-dynamic';
export const revalidate = 0;
export default function PrivacyPage() {
const page = getPageConfig('privacy');
if (!page) notFound();
+3
View File
@@ -45,6 +45,9 @@ export async function generateMetadata(): Promise<Metadata> {
};
}
export const dynamic = 'force-dynamic';
export const revalidate = 0;
export default function TrustPage() {
const page = getPageConfig('trust');
if (!page) notFound();
+37
View File
@@ -0,0 +1,37 @@
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export function middleware(request: NextRequest) {
const response = NextResponse.next();
const pathname = request.nextUrl.pathname;
// Don't override hashed Next.js static asset chunks (they are immutable by hash)
const isHashedStatic =
pathname.startsWith('/_next/static') ||
pathname.startsWith('/_next/image');
if (!isHashedStatic) {
// Strictly disable caching for all HTML pages, API responses, and routes
response.headers.set(
'Cache-Control',
'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0, s-maxage=0'
);
response.headers.set('Pragma', 'no-cache');
response.headers.set('Expires', '0');
response.headers.set('Surrogate-Control', 'no-store');
response.headers.set('CDN-Cache-Control', 'no-store');
response.headers.set('Cloudflare-CDN-Cache-Control', 'no-store');
response.headers.set('X-Deploy-Version', '20261117_sfpro');
}
return response;
}
export const config = {
matcher: [
/*
* Match all request paths except static files with extensions (.png, .jpg, .svg, etc.)
*/
'/((?!_next/static|_next/image|brand/|favicon.ico|manifest.webmanifest).*)',
],
};