This commit is contained in:
payacom
2026-07-23 15:58:15 +03:30
parent af5b27b610
commit a1d7db5e7e
445 changed files with 23456 additions and 8865 deletions

View File

@@ -1,61 +1,60 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
const CACHE_NAME = "pwa-cache-v4";
const CACHE_NAME = "pwa-cache-v10";
const PRECACHE_URLS = [
"/",
"/manifest.webmanifest",
"/manifest.json",
"/images/icons/192x192.png",
"/images/icons/256x256.png",
"/images/icons/512x512.png",
"/images/icons/apple-touch-icon.png",
"/images/icons/maskable-192.png",
"/images/icons/maskable-512.png",
"/favicon.png",
];
// نصب Service Worker
self.addEventListener("install", (event) => {
console.log("Service Worker installing...");
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => {
return cache.addAll([
"/",
"/manifest.json",
"/images/icons/256x256.png",
"/images/icons/512x512.png",
]);
})
caches.open(CACHE_NAME).then((cache) => cache.addAll(PRECACHE_URLS))
);
self.skipWaiting();
});
// فعال‌سازی Service Worker
self.addEventListener("activate", (event) => {
console.log("Service Worker activated.");
event.waitUntil(
caches
.keys()
.then((keys) =>
Promise.all(
keys
.filter((key) => key !== CACHE_NAME)
.map((key) => caches.delete(key))
keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key))
)
)
.then(() => self.clients.claim())
);
});
// هندل درخواست‌ها
self.addEventListener("fetch", (event) => {
const url = new URL(event.request.url);
// navigation: همیشه از شبکه — HTML کش نشود تا title/meta همیشه تازه باشد
if (event.request.mode === "navigate") {
event.respondWith(fetch(event.request));
return;
}
// آیکون‌ها: network-first
if (url.pathname.startsWith("/images/icons/")) {
if (
url.pathname.startsWith("/images/icons/") ||
url.pathname.endsWith("manifest.webmanifest") ||
url.pathname.endsWith("manifest.json") ||
url.pathname.endsWith("favicon.png")
) {
event.respondWith(
fetch(event.request)
.then((res) => {
if (res.ok) {
const clone = res.clone();
caches
.open(CACHE_NAME)
.then((cache) => cache.put(event.request, clone));
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone));
}
return res;
})
@@ -64,15 +63,13 @@ self.addEventListener("fetch", (event) => {
return;
}
// سایر فایل‌های استاتیک: stale-while-revalidate
if (
url.pathname.startsWith("/images/") ||
url.pathname.endsWith(".png") ||
url.pathname.endsWith(".jpg") ||
url.pathname.endsWith(".jpeg") ||
url.pathname.endsWith(".gif") ||
url.pathname.endsWith(".webp") ||
url.pathname.endsWith("manifest.json")
url.pathname.endsWith(".webp")
) {
event.respondWith(
caches.match(event.request).then((cached) => {