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
+10 -5
View File
@@ -62,18 +62,23 @@ const nextConfig = {
key: 'Content-Security-Policy', key: 'Content-Security-Policy',
value: [ value: [
"default-src 'self'", "default-src 'self'",
"script-src 'self' 'unsafe-inline' 'unsafe-eval' https://apis.google.com", "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://apis.google.com https://challenges.cloudflare.com",
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com", "style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://fonts.cdnfonts.com",
"font-src 'self' https://fonts.gstatic.com", "font-src 'self' https://fonts.gstatic.com https://fonts.cdnfonts.com data:",
"img-src 'self' data: blob: https:", "img-src 'self' data: blob: https:",
"connect-src 'self' https://*.firebaseapp.com https://*.googleapis.com https://identitytoolkit.googleapis.com https://securetoken.googleapis.com", "connect-src 'self' https://*.firebaseapp.com https://*.googleapis.com https://identitytoolkit.googleapis.com https://securetoken.googleapis.com https://challenges.cloudflare.com",
"frame-src 'self' https://accounts.google.com", "frame-src 'self' https://accounts.google.com https://challenges.cloudflare.com",
"object-src 'none'", "object-src 'none'",
"base-uri 'self'", "base-uri 'self'",
"form-action 'self'", "form-action 'self'",
...(isProd ? ["upgrade-insecure-requests"] : []), ...(isProd ? ["upgrade-insecure-requests"] : []),
].join('; '), ].join('; '),
}, },
// Strict Cache-Control to prevent browsers & CDNs from serving stale HTML
{ key: 'Cache-Control', value: 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0, s-maxage=0' },
{ key: 'Pragma', value: 'no-cache' },
{ key: 'Expires', value: '0' },
{ key: 'Surrogate-Control', value: 'no-store' },
// Block clickjacking // Block clickjacking
{ key: 'X-Frame-Options', value: 'SAMEORIGIN' }, { key: 'X-Frame-Options', value: 'SAMEORIGIN' },
// Prevent MIME sniffing // Prevent MIME sniffing
+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() { export default function AppsIndexPage() {
const page = getPageConfig('apps'); const page = getPageConfig('apps');
if (!page) notFound(); if (!page) notFound();
+39
View File
@@ -169,6 +169,45 @@ export default function RootLayout({
return ( return (
<html lang="en" className={`${poppinsFont.variable} ${interFont.variable} ${monoFont.variable} font-sans`}> <html lang="en" className={`${poppinsFont.variable} ${interFont.variable} ${monoFont.variable} font-sans`}>
<head> <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 <script
type="application/ld+json" type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(organizationJsonLd) }} 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() { export default function PrivacyPage() {
const page = getPageConfig('privacy'); const page = getPageConfig('privacy');
if (!page) notFound(); 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() { export default function TrustPage() {
const page = getPageConfig('trust'); const page = getPageConfig('trust');
if (!page) notFound(); 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).*)',
],
};