{"id":471073,"date":"2025-08-18T09:00:27","date_gmt":"2025-08-18T09:00:27","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=471073"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=471073","title":{"rendered":"<span>SW: stale-while-revalidate \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 + \u0433\u0438\u0441\u0442<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>Service Worker \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435: \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f stale-while-revalidate (+ \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0433\u0438\u0441\u0442)<\/h3>\n<h3>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 stale-while-revalidate (SWR)<\/h3>\n<p>\u0418\u0434\u0435\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u044f:<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u0440\u0430\u0437\u0443<\/strong> \u043e\u0442\u0434\u0430\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u0443\u0436\u0435 \u043b\u0435\u0436\u0438\u0442 \u0432 \u043a\u044d\u0448\u0435 (stale).<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e<\/strong> \u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0441\u0435\u0442\u044c \u0437\u0430 \u0441\u0432\u0435\u0436\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 (revalidate).<\/p>\n<\/li>\n<li>\n<p><strong>\u0411\u0435\u0441\u0448\u043e\u0432\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c<\/strong> \u043a\u044d\u0448 \u00ab\u0432 \u0444\u043e\u043d\u0435\u00bb, \u0447\u0442\u043e\u0431\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0437\u0438\u0442 \u0431\u044b\u043b \u0443\u0436\u0435 \u0441\u043e \u0441\u0432\u0435\u0436\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0438\u0434\u0438\u0442 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u043e\u0442\u043a\u043b\u0438\u043a, \u0430 \u043c\u044b \u2014 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u00ab\u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u043c\u00bb \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442.<\/p>\n<hr\/>\n<h3>\u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c SWR<\/h3>\n<ul>\n<li>\n<p><strong>\u0421\u0442\u0430\u0442\u0438\u043a\u0430<\/strong>: CSS\/JS\/\u0448\u0440\u0438\u0444\u0442\u044b\/\u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e CDN).<\/p>\n<\/li>\n<li>\n<p><strong>API, \u043d\u0435 \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e\u0435 \u043a \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u0439 \u0441\u0432\u0435\u0436\u0435\u0441\u0442\u0438<\/strong>: \u0442\u0435\u0433\u0438, \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0438, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u043d\u0435\u043b\u0438<\/strong> \u2014 \u0441 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u043c \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u043e\u043c \u0441\u0435\u0442\u0438 (\u0435\u0441\u043b\u0438 \u0441\u0435\u0442\u044c \u0434\u043e\u043b\u0433\u043e \u043c\u043e\u043b\u0447\u0438\u0442, \u0432\u0435\u0440\u043d\u0451\u043c \u043a\u044d\u0448 \u0438 \u043d\u0435 \u00ab\u0437\u0430\u043c\u043e\u0440\u043e\u0437\u0438\u043c\u00bb UI).<\/p>\n<\/li>\n<\/ul>\n<p>\u0413\u0434\u0435 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442: <strong>HTML-\u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438<\/strong>. \u0414\u043b\u044f \u043d\u0438\u0445 \u043b\u0443\u0447\u0448\u0435 <code>network-first<\/code> c \u043e\u0444\u043b\u0430\u0439\u043d-\u0444\u043e\u043b\u0431\u044d\u043a\u043e\u043c \u2014 \u0438\u043d\u0430\u0447\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043b\u0433\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<hr\/>\n<h4>\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f<\/h4>\n<pre><code class=\"javascript\">&lt;!-- register-sw.js --&gt; &lt;script src=\"\/register-sw.js\" defer&gt;&lt;\/script&gt; <\/code><\/pre>\n<pre><code class=\"javascript\">\/\/ register-sw.js (\u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442) if ('serviceWorker' in navigator) {   window.addEventListener('load', async () =&gt; {     const reg = await navigator.serviceWorker.register('\/sw.js', { scope: '\/' });      \/\/ \u0423\u0432\u0435\u0434\u043e\u043c\u0438\u043c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u0447\u0442\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 SW     reg.addEventListener('updatefound', () =&gt; {       const sw = reg.installing;       sw?.addEventListener('statechange', () =&gt; {         if (sw.state === 'installed' &amp;&amp; navigator.serviceWorker.controller) {           window.dispatchEvent(new CustomEvent('sw.update.available'));         }       });     });   });    \/\/ \u041f\u043e \u043a\u043b\u0438\u043a\u0443 \u00ab\u041e\u0431\u043d\u043e\u0432\u0438\u0442\u044c\u00bb \u043c\u043e\u0436\u043d\u043e \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e:   window.activateNewSW = async () =&gt; {     const reg = await navigator.serviceWorker.getRegistration();     reg?.waiting?.postMessage('SKIP_WAITING');   }; } <\/code><\/pre>\n<h4>\u0421\u0430\u043c Service Worker<\/h4>\n<pre><code class=\"javascript\">\/* sw.js \u2014 \u0431\u0430\u0437\u043e\u0432\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f SWR *\/ const VERSION = 'v1.0.0'; const STATIC_CACHE  = `static-${VERSION}`; const RUNTIME_CACHE = `runtime-${VERSION}`;  const PRECACHE = ['\/', '\/offline.html'];  self.addEventListener('install', (e) =&gt; {   self.skipWaiting();   e.waitUntil(caches.open(STATIC_CACHE).then((c) =&gt; c.addAll(PRECACHE))); });  self.addEventListener('activate', (e) =&gt; {   e.waitUntil((async () =&gt; {     const keep = new Set([STATIC_CACHE, RUNTIME_CACHE]);     const keys = await caches.keys();     await Promise.all(keys.map((k) =&gt; keep.has(k) ? null : caches.delete(k)));     await self.clients.claim();   })()); });  self.addEventListener('message', (e) =&gt; {   if (e.data === 'SKIP_WAITING') self.skipWaiting(); });  self.addEventListener('fetch', (event) =&gt; {   const req = event.request;   if (req.method !== 'GET') return;    const url = new URL(req.url);    \/\/ HTML-\u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u2014 network-first + \u043e\u0444\u043b\u0430\u0439\u043d-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430   if (req.mode === 'navigate') {     event.respondWith((async () =&gt; {       try {         const fresh = await fetch(req);         (await caches.open(RUNTIME_CACHE)).put(req, fresh.clone());         return fresh;       } catch {         return (await caches.open(STATIC_CACHE)).match('\/offline.html');       }     })());     return;   }    \/\/ \u0421\u0442\u0430\u0442\u0438\u043a\u0430 \u0438 API \u2014 SWR   const isAsset = ['style','script','image','font'].includes(req.destination) ||                   url.pathname.match(\/\\.(css|js|mjs|woff2?|ttf|otf|png|jpe?g|webp|avif|svg)$\/i);   const isApi = url.origin === self.location.origin &amp;&amp; url.pathname.startsWith('\/api\/');    if (isAsset || isApi) {     event.respondWith(staleWhileRevalidate(req, RUNTIME_CACHE, {       ignoreSearch: req.destination === 'image',       networkTimeoutMs: isApi ? 2000 : undefined     }));   } });  async function staleWhileRevalidate(request, cacheName, opts = {}) {   const cache = await caches.open(cacheName);   const cachedPromise = cache.match(request, { ignoreSearch: !!opts.ignoreSearch });    const networkPromise = (async () =&gt; {     try {       let controller, signal;       if (opts.networkTimeoutMs) {         controller = new AbortController();         signal = controller.signal;         setTimeout(() =&gt; controller.abort(), opts.networkTimeoutMs);       }       const res = await fetch(request, signal ? { signal } : undefined);       if (res &amp;&amp; (res.ok || res.type === 'opaque')) cache.put(request, res.clone());       return res;     } catch { return null; }   })();    const cached = await cachedPromise;   if (cached) { networkPromise; return cached; }      \/\/ \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e \u043e\u0442\u0434\u0430\u0451\u043c \u043a\u044d\u0448   const network = await networkPromise;               \/\/ \u0438\u043d\u0430\u0447\u0435 \u0436\u0434\u0451\u043c \u0441\u0435\u0442\u044c   return network || new Response('', { status: 504 }); } <\/code><\/pre>\n<h4>\u0421\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0434\u043b\u044f sw.js<\/h4>\n<pre><code class=\"nginx\"># nginx-snippet.conf location = \/sw.js {   add_header Cache-Control \"no-store, max-age=0, must-revalidate\" always; } <\/code><\/pre>\n<hr\/>\n<h3>\u041e\u0442\u043b\u0430\u0434\u043a\u0430 \u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435<\/h3>\n<ul>\n<li>\n<p><strong>Chrome DevTools \u2192 Application \u2192 Service Workers<\/strong>: \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435, \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430, \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044f offline.<\/p>\n<\/li>\n<li>\n<p><strong>Network \u2192 Disable cache<\/strong>: \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u0435\u0442\u0435\u0432\u043e\u0433\u043e \u043f\u0443\u0442\u0438 \u0431\u0435\u0437 \u0432\u043b\u0438\u044f\u043d\u0438\u044f HTTP-\u043a\u044d\u0448\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>Application \u2192 Cache Storage<\/strong>: \u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043b\u0435\u0436\u0438\u0442 \u0432 \u043a\u044d\u0448\u0435 SW.<\/p>\n<\/li>\n<li>\n<p><strong>\u041b\u043e\u0433\u0438<\/strong>: \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 <code>console.log<\/code> \u0432 SW (\u0432\u0438\u0434\u043d\u043e \u0432 DevTools \u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0439 \u0432\u043a\u043b\u0430\u0434\u043a\u0435 SW).<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>\u0427\u0430\u0441\u0442\u044b\u0435 \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u0438 \u0438 \u0433\u0440\u0430\u0431\u043b\u0438<\/h3>\n<ul>\n<li>\n<p><strong>Opaque-\u043e\u0442\u0432\u0435\u0442\u044b<\/strong> (<code>no-cors<\/code>) \u043a\u044d\u0448\u0438\u0440\u0443\u044e\u0442\u0441\u044f, \u043d\u043e \u0438\u0445 \u043d\u0435\u043b\u044c\u0437\u044f \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c; \u0440\u0435\u0448\u0430\u0439\u0442\u0435 \u043f\u043e \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u0435\u0440\u0441\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u044d\u0448\u0435\u0439<\/strong>: \u043c\u0435\u043d\u044f\u0439\u0442\u0435 <code>VERSION<\/code> \u043f\u0440\u0438 \u0440\u0435\u043b\u0438\u0437\u0435, \u0447\u0438\u0441\u0442\u0438\u0442\u0435 \u0441\u0442\u0430\u0440\u044b\u0435 \u043a\u044d\u0448\u0438 \u0432 <code>activate<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>HTML \u0438 SWR \u2014 \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e<\/strong>: \u0434\u043b\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u043b\u0443\u0447\u0448\u0435 <code>network-first<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u00ab\u0437\u0430\u0441\u0442\u0440\u044f\u043b\u00bb \u043d\u0430 \u0441\u0442\u0430\u0440\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u0432\u043e\u0442\u044b \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430<\/strong>: \u043d\u0430 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u0445 \u043c\u0435\u0441\u0442\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043e; \u0434\u043b\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u044d\u043a\u0441\u043f\u0438\u0440\u0430\u0446\u0438\u044e (\u0441\u043c. Workbox \u0438\u043b\u0438 IDB-\u043f\u043b\u0430\u0433\u0438\u043d).<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u0430\u0432\u0438\u043b\u0430 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/strong>: \u043d\u0435 \u043a\u0435\u0448\u0438\u0440\u0443\u0439\u0442\u0435 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b (\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u0430\u0431\u0438\u043d\u0435\u0442) \u0431\u0435\u0437 \u044f\u0432\u043d\u043e\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>\u041a\u0430\u043a \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u00ab\u0441\u0440\u043e\u043a \u0433\u043e\u0434\u043d\u043e\u0441\u0442\u0438\u00bb \u0431\u0435\u0437 Workbox<\/h3>\n<p>Workbox \u0440\u0435\u0448\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e (<code>ExpirationPlugin<\/code>), \u043d\u043e \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u0435\u043d \u0432\u0430\u043d\u0438\u043b\u044c\u043d\u044b\u0439 SW, \u0437\u0430\u0432\u0435\u0434\u0438\u0442\u0435 \u043c\u0438\u043d\u0438-\u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0432 <strong>IndexedDB<\/strong> (\u043a\u043b\u044e\u0447 = URL, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 = timestamp) \u0438 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u0434\u0430\u043b\u044f\u0439\u0442\u0435 \u0441\u0442\u0430\u0440\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438:<\/p>\n<pre><code class=\"javascript\">\/\/ \u041f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434: \u043f\u043e\u0441\u043b\u0435 cache.put(request, responseClone) await idb.set(request.url, Date.now()); \/\/ \u0433\u0434\u0435-\u0442\u043e \u0432 activate\/fetch: \u043f\u0440\u043e\u0431\u0435\u0433\u0438\u0442\u0435\u0441\u044c \u043f\u043e \u043a\u043b\u044e\u0447\u0430\u043c \u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u0435 \u043f\u0440\u043e\u0441\u0440\u043e\u0447\u0435\u043d\u043d\u044b\u0435 <\/code><\/pre>\n<p>\u042d\u0442\u043e 30\u201340 \u0441\u0442\u0440\u043e\u043a \u0441 idb-keyval \u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0430\u0432\u0438\u043b (<code>maxAgeSeconds<\/code>, <code>maxEntries<\/code>).<\/p>\n<hr\/>\n<h3>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u044d\u0444\u0444\u0435\u043a\u0442\u0430: \u0447\u0442\u043e \u0434\u0430\u0441\u0442 SWR<\/h3>\n<ul>\n<li>\n<p><strong>\u0412\u0440\u0435\u043c\u044f \u0434\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/strong> (\u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0435 \u0432\u0438\u0437\u0438\u0442\u044b) \u2192 \u0440\u0435\u0437\u043a\u043e \u043f\u0430\u0434\u0430\u0435\u0442.<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043d\u0430 \u0431\u044d\u043a\u0435\u043d\u0434\/CDN<\/strong> \u2192 \u0441\u043d\u0438\u0436\u0430\u0435\u0442\u0441\u044f \u0437\u0430 \u0441\u0447\u0451\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u043d\u0438\u044f \u0432 \u043a\u044d\u0448 SW.<\/p>\n<\/li>\n<li>\n<p><strong>CWV<\/strong>: \u043a\u043e\u0441\u0432\u0435\u043d\u043d\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 LCP\/INP \u043d\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u044f\u0445 (\u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0441\u0442\u0430\u0442\u0438\u043a\u0430).<\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p>\u041f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 + Nginx-\u0441\u043d\u0438\u043f\u043f\u0435\u0442 \u043b\u0435\u0436\u0438\u0442 \u0432 \u0430\u0440\u0445\u0438\u0432\u0435:<br \/> <a href=\"https:\/\/github.com\/joewebkid\/download\/blob\/main\/sw-stale-while-revalidate-gist.zip\" rel=\"noopener noreferrer nofollow\"><strong>\u0421\u043a\u0430\u0447\u0430\u0442\u044c zip<\/strong><\/a><br \/> (\u0444\u0430\u0439\u043b\u044b: <code>sw.js<\/code>, <code>register-sw.js<\/code>, <code>offline.html<\/code>, <code>nginx-snippet.conf<\/code>)<\/p>\n<\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/938060\/\"> https:\/\/habr.com\/ru\/articles\/938060\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>Service Worker \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435: \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f stale-while-revalidate (+ \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0433\u0438\u0441\u0442)<\/h3>\n<h3>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 stale-while-revalidate (SWR)<\/h3>\n<p>\u0418\u0434\u0435\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u044f:<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u0440\u0430\u0437\u0443<\/strong> \u043e\u0442\u0434\u0430\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u0443\u0436\u0435 \u043b\u0435\u0436\u0438\u0442 \u0432 \u043a\u044d\u0448\u0435 (stale).<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e<\/strong> \u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0441\u0435\u0442\u044c \u0437\u0430 \u0441\u0432\u0435\u0436\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 (revalidate).<\/p>\n<\/li>\n<li>\n<p><strong>\u0411\u0435\u0441\u0448\u043e\u0432\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c<\/strong> \u043a\u044d\u0448 \u00ab\u0432 \u0444\u043e\u043d\u0435\u00bb, \u0447\u0442\u043e\u0431\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0437\u0438\u0442 \u0431\u044b\u043b \u0443\u0436\u0435 \u0441\u043e \u0441\u0432\u0435\u0436\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0438\u0434\u0438\u0442 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u043e\u0442\u043a\u043b\u0438\u043a, \u0430 \u043c\u044b \u2014 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u00ab\u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u043c\u00bb \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442.<\/p>\n<hr\/>\n<h3>\u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c SWR<\/h3>\n<ul>\n<li>\n<p><strong>\u0421\u0442\u0430\u0442\u0438\u043a\u0430<\/strong>: CSS\/JS\/\u0448\u0440\u0438\u0444\u0442\u044b\/\u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e CDN).<\/p>\n<\/li>\n<li>\n<p><strong>API, \u043d\u0435 \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e\u0435 \u043a \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u0439 \u0441\u0432\u0435\u0436\u0435\u0441\u0442\u0438<\/strong>: \u0442\u0435\u0433\u0438, \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0438, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u043d\u0435\u043b\u0438<\/strong> \u2014 \u0441 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u043c \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u043e\u043c \u0441\u0435\u0442\u0438 (\u0435\u0441\u043b\u0438 \u0441\u0435\u0442\u044c \u0434\u043e\u043b\u0433\u043e \u043c\u043e\u043b\u0447\u0438\u0442, \u0432\u0435\u0440\u043d\u0451\u043c \u043a\u044d\u0448 \u0438 \u043d\u0435 \u00ab\u0437\u0430\u043c\u043e\u0440\u043e\u0437\u0438\u043c\u00bb UI).<\/p>\n<\/li>\n<\/ul>\n<p>\u0413\u0434\u0435 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442: <strong>HTML-\u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438<\/strong>. \u0414\u043b\u044f \u043d\u0438\u0445 \u043b\u0443\u0447\u0448\u0435 <code>network-first<\/code> c \u043e\u0444\u043b\u0430\u0439\u043d-\u0444\u043e\u043b\u0431\u044d\u043a\u043e\u043c \u2014 \u0438\u043d\u0430\u0447\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043b\u0433\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<hr\/>\n<h4>\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f<\/h4>\n<pre><code class=\"javascript\">&lt;!-- register-sw.js --&gt; &lt;script src=\"\/register-sw.js\" defer&gt;&lt;\/script&gt; <\/code><\/pre>\n<pre><code class=\"javascript\">\/\/ register-sw.js (\u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442) if ('serviceWorker' in navigator) {   window.addEventListener('load', async () =&gt; {     const reg = await navigator.serviceWorker.register('\/sw.js', { scope: '\/' });      \/\/ \u0423\u0432\u0435\u0434\u043e\u043c\u0438\u043c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u0447\u0442\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 SW     reg.addEventListener('updatefound', () =&gt; {       const sw = reg.installing;       sw?.addEventListener('statechange', () =&gt; {         if (sw.state === 'installed' &amp;&amp; navigator.serviceWorker.controller) {           window.dispatchEvent(new CustomEvent('sw.update.available'));         }       });     });   });    \/\/ \u041f\u043e \u043a\u043b\u0438\u043a\u0443 \u00ab\u041e\u0431\u043d\u043e\u0432\u0438\u0442\u044c\u00bb \u043c\u043e\u0436\u043d\u043e \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e:   window.activateNewSW = async () =&gt; {     const reg = await navigator.serviceWorker.getRegistration();     reg?.waiting?.postMessage('SKIP_WAITING');   }; } <\/code><\/pre>\n<h4>\u0421\u0430\u043c Service Worker<\/h4>\n<pre><code class=\"javascript\">\/* sw.js \u2014 \u0431\u0430\u0437\u043e\u0432\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f SWR *\/ const VERSION = 'v1.0.0'; const STATIC_CACHE  = `static-${VERSION}`; const RUNTIME_CACHE = `runtime-${VERSION}`;  const PRECACHE = ['\/', '\/offline.html'];  self.addEventListener('install', (e) =&gt; {   self.skipWaiting();   e.waitUntil(caches.open(STATIC_CACHE).then((c) =&gt; c.addAll(PRECACHE))); });  self.addEventListener('activate', (e) =&gt; {   e.waitUntil((async () =&gt; {     const keep = new Set([STATIC_CACHE, RUNTIME_CACHE]);     const keys = await caches.keys();     await Promise.all(keys.map((k) =&gt; keep.has(k) ? null : caches.delete(k)));     await self.clients.claim();   })()); });  self.addEventListener('message', (e) =&gt; {   if (e.data === 'SKIP_WAITING') self.skipWaiting(); });  self.addEventListener('fetch', (event) =&gt; {   const req = event.request;   if (req.method !== 'GET') return;    const url = new URL(req.url);    \/\/ HTML-\u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u2014 network-first + \u043e\u0444\u043b\u0430\u0439\u043d-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430   if (req.mode === 'navigate') {     event.respondWith((async () =&gt; {       try {         const fresh = await fetch(req);         (await caches.open(RUNTIME_CACHE)).put(req, fresh.clone());         return fresh;       } catch {         return (await caches.open(STATIC_CACHE)).match('\/offline.html');       }     })());     return;   }    \/\/ \u0421\u0442\u0430\u0442\u0438\u043a\u0430 \u0438 API \u2014 SWR   const isAsset = ['style','script','image','font'].includes(req.destination) ||                   url.pathname.match(\/\\.(css|js|mjs|woff2?|ttf|otf|png|jpe?g|webp|avif|svg)$\/i);   const isApi = url.origin === self.location.origin &amp;&amp; url.pathname.startsWith('\/api\/');    if (isAsset || isApi) {     event.respondWith(staleWhileRevalidate(req, RUNTIME_CACHE, {       ignoreSearch: req.destination === 'image',       networkTimeoutMs: isApi ? 2000 : undefined     }));   } });  async function staleWhileRevalidate(request, cacheName, opts = {}) {   const cache = await caches.open(cacheName);   const cachedPromise = cache.match(request, { ignoreSearch: !!opts.ignoreSearch });    const networkPromise = (async () =&gt; {     try {       let controller, signal;       if (opts.networkTimeoutMs) {         controller = new AbortController();         signal = controller.signal;         setTimeout(() =&gt; controller.abort(), opts.networkTimeoutMs);       }       const res = await fetch(request, signal ? { signal } : undefined);       if (res &amp;&amp; (res.ok || res.type === 'opaque')) cache.put(request, res.clone());       return res;     } catch { return null; }   })();    const cached = await cachedPromise;   if (cached) { networkPromise; return cached; }      \/\/ \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e \u043e\u0442\u0434\u0430\u0451\u043c \u043a\u044d\u0448   const network = await networkPromise;               \/\/ \u0438\u043d\u0430\u0447\u0435 \u0436\u0434\u0451\u043c \u0441\u0435\u0442\u044c   return network || new Response('', { status: 504 }); } <\/code><\/pre>\n<h4>\u0421\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0434\u043b\u044f sw.js<\/h4>\n<pre><code class=\"nginx\"># nginx-snippet.conf location = \/sw.js {   add_header Cache-Control \"no-store, max-age=0, must-revalidate\" always; } <\/code><\/pre>\n<hr\/>\n<h3>\u041e\u0442\u043b\u0430\u0434\u043a\u0430 \u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435<\/h3>\n<ul>\n<li>\n<p><strong>Chrome DevTools \u2192 Application \u2192 Service Workers<\/strong>: \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435, \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430, \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044f offline.<\/p>\n<\/li>\n<li>\n<p><strong>Network \u2192 Disable cache<\/strong>: \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u0435\u0442\u0435\u0432\u043e\u0433\u043e \u043f\u0443\u0442\u0438 \u0431\u0435\u0437 \u0432\u043b\u0438\u044f\u043d\u0438\u044f HTTP-\u043a\u044d\u0448\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>Application \u2192 Cache Storage<\/strong>: \u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043b\u0435\u0436\u0438\u0442 \u0432 \u043a\u044d\u0448\u0435 SW.<\/p>\n<\/li>\n<li>\n<p><strong>\u041b\u043e\u0433\u0438<\/strong>: \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 <code>console.log<\/code> \u0432 SW (\u0432\u0438\u0434\u043d\u043e \u0432 DevTools \u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0439 \u0432\u043a\u043b\u0430\u0434\u043a\u0435 SW).<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>\u0427\u0430\u0441\u0442\u044b\u0435 \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u0438 \u0438 \u0433\u0440\u0430\u0431\u043b\u0438<\/h3>\n<ul>\n<li>\n<p><strong>Opaque-\u043e\u0442\u0432\u0435\u0442\u044b<\/strong> (<code>no-cors<\/code>) \u043a\u044d\u0448\u0438\u0440\u0443\u044e\u0442\u0441\u044f, \u043d\u043e \u0438\u0445 \u043d\u0435\u043b\u044c\u0437\u044f \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c; \u0440\u0435\u0448\u0430\u0439\u0442\u0435 \u043f\u043e \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u0435\u0440\u0441\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u044d\u0448\u0435\u0439<\/strong>: \u043c\u0435\u043d\u044f\u0439\u0442\u0435 <code>VERSION<\/code> \u043f\u0440\u0438 \u0440\u0435\u043b\u0438\u0437\u0435, \u0447\u0438\u0441\u0442\u0438\u0442\u0435 \u0441\u0442\u0430\u0440\u044b\u0435 \u043a\u044d\u0448\u0438 \u0432 <code>activate<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>HTML \u0438 SWR \u2014 \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e<\/strong>: \u0434\u043b\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u043b\u0443\u0447\u0448\u0435 <code>network-first<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u00ab\u0437\u0430\u0441\u0442\u0440\u044f\u043b\u00bb \u043d\u0430 \u0441\u0442\u0430\u0440\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u0432\u043e\u0442\u044b \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430<\/strong>: \u043d\u0430 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u0445 \u043c\u0435\u0441\u0442\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043e; \u0434\u043b\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u044d\u043a\u0441\u043f\u0438\u0440\u0430\u0446\u0438\u044e (\u0441\u043c. Workbox \u0438\u043b\u0438 IDB-\u043f\u043b\u0430\u0433\u0438\u043d).<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u0430\u0432\u0438\u043b\u0430 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/strong>: \u043d\u0435 \u043a\u0435\u0448\u0438\u0440\u0443\u0439\u0442\u0435 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b (\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u0430\u0431\u0438\u043d\u0435\u0442) \u0431\u0435\u0437 \u044f\u0432\u043d\u043e\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>\u041a\u0430\u043a \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u00ab\u0441\u0440\u043e\u043a \u0433\u043e\u0434\u043d\u043e\u0441\u0442\u0438\u00bb \u0431\u0435\u0437 Workbox<\/h3>\n<p>Workbox \u0440\u0435\u0448\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e (<code>ExpirationPlugin<\/code>), \u043d\u043e \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u0435\u043d \u0432\u0430\u043d\u0438\u043b\u044c\u043d\u044b\u0439 SW, \u0437\u0430\u0432\u0435\u0434\u0438\u0442\u0435 \u043c\u0438\u043d\u0438-\u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0432 <strong>IndexedDB<\/strong> (\u043a\u043b\u044e\u0447 = URL, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 = timestamp) \u0438 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u0434\u0430\u043b\u044f\u0439\u0442\u0435 \u0441\u0442\u0430\u0440\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438:<\/p>\n<pre><code class=\"javascript\">\/\/ \u041f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434: \u043f\u043e\u0441\u043b\u0435 cache.put(request, responseClone) await idb.set(request.url, Date.now()); \/\/ \u0433\u0434\u0435-\u0442\u043e \u0432 activate\/fetch: \u043f\u0440\u043e\u0431\u0435\u0433\u0438\u0442\u0435\u0441\u044c \u043f\u043e \u043a\u043b\u044e\u0447\u0430\u043c \u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u0435 \u043f\u0440\u043e\u0441\u0440\u043e\u0447\u0435\u043d\u043d\u044b\u0435 <\/code><\/pre>\n<p>\u042d\u0442\u043e 30\u201340 \u0441\u0442\u0440\u043e\u043a \u0441 idb-keyval \u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0430\u0432\u0438\u043b (<code>maxAgeSeconds<\/code>, <code>maxEntries<\/code>).<\/p>\n<hr\/>\n<h3>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u044d\u0444\u0444\u0435\u043a\u0442\u0430: \u0447\u0442\u043e \u0434\u0430\u0441\u0442 SWR<\/h3>\n<ul>\n<li>\n<p><strong>\u0412\u0440\u0435\u043c\u044f \u0434\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/strong> (\u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0435 \u0432\u0438\u0437\u0438\u0442\u044b) \u2192 \u0440\u0435\u0437\u043a\u043e \u043f\u0430\u0434\u0430\u0435\u0442.<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043d\u0430 \u0431\u044d\u043a\u0435\u043d\u0434\/CDN<\/strong> \u2192 \u0441\u043d\u0438\u0436\u0430\u0435\u0442\u0441\u044f \u0437\u0430 \u0441\u0447\u0451\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u043d\u0438\u044f \u0432 \u043a\u044d\u0448 SW.<\/p>\n<\/li>\n<li>\n<p><strong>CWV<\/strong>: \u043a\u043e\u0441\u0432\u0435\u043d\u043d\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 LCP\/INP \u043d\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u044f\u0445 (\u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0441\u0442\u0430\u0442\u0438\u043a\u0430).<\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p>\u041f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 + Nginx-\u0441\u043d\u0438\u043f\u043f\u0435\u0442 \u043b\u0435\u0436\u0438\u0442 \u0432 \u0430\u0440\u0445\u0438\u0432\u0435:<br \/> <a href=\"https:\/\/github.com\/joewebkid\/download\/blob\/main\/sw-stale-while-revalidate-gist.zip\" rel=\"noopener noreferrer nofollow\"><strong>\u0421\u043a\u0430\u0447\u0430\u0442\u044c zip<\/strong><\/a><br \/> (\u0444\u0430\u0439\u043b\u044b: <code>sw.js<\/code>, <code>register-sw.js<\/code>, <code>offline.html<\/code>, <code>nginx-snippet.conf<\/code>)<\/p>\n<\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/938060\/\"> https:\/\/habr.com\/ru\/articles\/938060\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-471073","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/471073","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=471073"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/471073\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=471073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=471073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=471073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}