This commit is contained in:
payacom
2026-07-10 18:17:11 +03:30
parent ce1becc392
commit 2863cdf490
13 changed files with 121 additions and 78 deletions

View File

@@ -1,33 +1,35 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
const CACHE_NAME = "pwa-cache-v2";
// نصب Service Worker
self.addEventListener("install", (event) => {
console.log("Service Worker installing...");
event.waitUntil(
caches.open("pwa-cache-v1").then((cache) => {
caches.open(CACHE_NAME).then((cache) => {
return cache.addAll([
"/",
"/manifest.json",
"/images/icons/256x256.png",
"/images/icons/512x512.png"
"/images/icons/512x512.png",
]);
})
);
self.skipWaiting();
});
// فعال‌سازی Service Worker
self.addEventListener("activate", (event) => {
console.log("Service Worker activated.");
// پاک کردن cacheهای قدیمی
event.waitUntil(
caches.keys().then((keys) =>
Promise.all(
keys
.filter((key) => key !== "pwa-cache-v1")
.filter((key) => key !== CACHE_NAME)
.map((key) => caches.delete(key))
)
)
).then(() => self.clients.claim())
);
});
@@ -35,7 +37,23 @@ self.addEventListener("activate", (event) => {
self.addEventListener("fetch", (event) => {
const url = new URL(event.request.url);
// فقط برای فایل‌های استاتیک از cache استفاده کن
// آیکون‌ها: network-first تا تغییرات فوری اعمال شوند
if (url.pathname.startsWith("/images/icons/")) {
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));
}
return res;
})
.catch(() => caches.match(event.request))
);
return;
}
// سایر فایل‌های استاتیک: stale-while-revalidate
if (
url.pathname.startsWith("/images/") ||
url.pathname.endsWith(".png") ||
@@ -46,17 +64,15 @@ self.addEventListener("fetch", (event) => {
url.pathname.endsWith("manifest.json")
) {
event.respondWith(
caches.match(event.request).then((response) => {
return (
response ||
fetch(event.request).then((res) => {
// فایل جدید رو هم ذخیره کن
return caches.open("pwa-cache-v1").then((cache) => {
cache.put(event.request, res.clone());
return res;
});
})
);
caches.match(event.request).then((cached) => {
const networkFetch = fetch(event.request).then((res) => {
if (res.ok) {
const clone = res.clone();
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone));
}
return res;
});
return cached || networkFetch;
})
);
}

View File

@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url><loc>https://modstagram.com/robots.txt</loc><lastmod>2026-07-08T17:38:00.874Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://modstagram.com/sitemap.xml</loc><lastmod>2026-07-08T17:38:00.875Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://modstagram.com/explore</loc><lastmod>2026-07-08T17:38:00.875Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://modstagram.com/academy/payment/failed</loc><lastmod>2026-07-08T17:38:00.875Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://modstagram.com/about-us</loc><lastmod>2026-07-08T17:38:00.875Z</lastmod><changefreq>monthly</changefreq><priority>0.8</priority></url>
<url><loc>https://modstagram.com/academy/payment/success</loc><lastmod>2026-07-08T17:38:00.875Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://modstagram.com/sitemap.xml</loc><lastmod>2026-07-10T11:28:38.990Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://modstagram.com/robots.txt</loc><lastmod>2026-07-10T11:28:38.990Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://modstagram.com/explore</loc><lastmod>2026-07-10T11:28:38.991Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://modstagram.com/academy/payment/success</loc><lastmod>2026-07-10T11:28:38.991Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://modstagram.com/about-us</loc><lastmod>2026-07-10T11:28:38.991Z</lastmod><changefreq>monthly</changefreq><priority>0.8</priority></url>
<url><loc>https://modstagram.com/academy/payment/failed</loc><lastmod>2026-07-10T11:28:38.991Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://modstagram.com</loc><changefreq>daily</changefreq><priority>1</priority></url>
<url><loc>https://modstagram.com/projects</loc><changefreq>daily</changefreq><priority>0.9</priority></url>
<url><loc>https://modstagram.com/billboards</loc><changefreq>daily</changefreq><priority>0.9</priority></url>