diff --git a/src/JobsMedical.Web/Pages/Shared/_Layout.cshtml b/src/JobsMedical.Web/Pages/Shared/_Layout.cshtml index a22b777..57ac3f0 100644 --- a/src/JobsMedical.Web/Pages/Shared/_Layout.cshtml +++ b/src/JobsMedical.Web/Pages/Shared/_Layout.cshtml @@ -221,7 +221,16 @@ @* Register the PWA service worker (offline + push notifications). *@ diff --git a/src/JobsMedical.Web/Program.cs b/src/JobsMedical.Web/Program.cs index 96ae0d1..a735a10 100644 --- a/src/JobsMedical.Web/Program.cs +++ b/src/JobsMedical.Web/Program.cs @@ -335,7 +335,12 @@ app.MapPost("/like", async (HttpContext ctx, AppDbContext db, [FromForm] string return Results.Json(new { liked, count }); }).RequireAuthorization().DisableAntiforgery(); -app.MapGet("/sw.js", () => Results.Content(""" +app.MapGet("/sw.js", (HttpContext ctx) => +{ + // The worker file must NEVER be cached — otherwise an old worker keeps serving stale pages and + // browsers never pick up a new version (the fix can't reach clients because the file is cached). + ctx.Response.Headers.CacheControl = "no-cache, no-store, must-revalidate"; + return Results.Content(""" const CACHE = 'hamkadr-v2'; const OFFLINE = 'آفلاین

اتصال اینترنت برقرار نیست

صفحه باز نشد؛ اتصال خود را بررسی و دوباره تلاش کنید.

'; self.addEventListener('install', e => { self.skipWaiting(); e.waitUntil(caches.open(CACHE).then(c => c.add('/'))); }); @@ -368,7 +373,8 @@ self.addEventListener('notificationclick', e => { const url = (e.notification.data && e.notification.data.url) || '/'; e.waitUntil(clients.matchAll({ type: 'window' }).then(cl => { for (const c of cl) { if ('focus' in c) { c.navigate(url); return c.focus(); } } return clients.openWindow(url); })); }); -""", "text/javascript")); +""", "text/javascript"); +}); // ---- SEO: robots.txt + dynamic sitemap.xml (so Google indexes every live shift/job page) ---- app.MapGet("/robots.txt", (HttpContext ctx) =>