@@ -354,32 +354,7 @@ async function putPagesInCache(cacheKey, pages, loadRelated = true) {
354354
355355// Стратегия кеширования
356356async function cacheStrategyImpl ( { cacheKey, request, preloadResponsePromise, fallbackUrl } ) {
357- let requestUrl = request . url
358-
359- // Игнорирует запросы на другие домены
360- if ( ! requestUrl . startsWith ( self . location . origin ) ) {
361- return new Response ( )
362- }
363-
364- // Игнорирует кеширование запросов методом POST
365- if ( request . method === 'POST' ) {
366- return new Response ( )
367- }
368-
369- // Игнорирует кеширование Service Worker
370- if ( requestUrl . endsWith ( 'sw.js' ) ) {
371- return new Response ( )
372- }
373-
374- // Игнорирует кеширование манифеста
375- if ( requestUrl . endsWith ( 'manifest.json' ) ) {
376- return new Response ( )
377- }
378-
379- // Игнорирует кеширование страниц с параметрами GET запроса
380- if ( requestUrl . indexOf ( '.html?' ) > - 1 || requestUrl . indexOf ( '.js?' ) > - 1 ) {
381- return new Response ( )
382- }
357+ let requestedUrl = request . url
383358
384359 // Пробует загрузить ресурс из кеша
385360 const responseFromCache = await caches . match ( request )
@@ -388,21 +363,21 @@ async function cacheStrategyImpl({ cacheKey, request, preloadResponsePromise, fa
388363 }
389364
390365 // Обрабатывает URL для кеширование страниц, если адрес заканчивается на 'index.html'
391- if ( requestUrl . endsWith ( 'index.html' ) ) {
392- requestUrl = requestUrl . replace ( 'index.html' , '' )
366+ if ( requestedUrl . endsWith ( 'index.html' ) ) {
367+ requestedUrl = requestedUrl . replace ( 'index.html' , '' )
393368 }
394369
395370 // Пробует получить ресурс из сети, если не получилось загрузить из кеша
396371 try {
397372 // Пробует воспользоваться предварительно загруженным ресурсом, если не получилось загрузить из кеша
398373 const preloadResponse = await preloadResponsePromise
399374 if ( preloadResponse ) {
400- cloneResponseInCache ( cacheKey , requestUrl , preloadResponse )
375+ cloneResponseInCache ( cacheKey , requestedUrl , preloadResponse )
401376 return preloadResponse
402377 }
403378
404379 // Запрашиваемый пользователем ресурс загружается и помещается в кеш
405- return putResInCache ( cacheKey , requestUrl )
380+ return putResInCache ( cacheKey , request )
406381 } catch ( error ) {
407382 // Если ресурс загрузить не получилось, показывается страница с уведомлением об отсутствии сети
408383 const fallbackResponse = await caches . match ( fallbackUrl )
@@ -459,6 +434,26 @@ self.addEventListener('message', async (event) => {
459434} )
460435
461436self . addEventListener ( 'fetch' , async ( event ) => {
437+ // Игнорирует запросы на другие домены
438+ if ( ! event . request . startsWith ( self . location . origin ) && event . request . method === 'POST' ) {
439+ return new Response ( fetch ( event . request ) )
440+ }
441+
442+ // Игнорирует кеширование Service Worker
443+ if ( event . request . endsWith ( 'sw.js' ) ) {
444+ return new Response ( fetch ( event . request ) )
445+ }
446+
447+ // Игнорирует кеширование манифеста
448+ if ( event . request . endsWith ( 'manifest.json' ) ) {
449+ return new Response ( fetch ( event . request ) )
450+ }
451+
452+ // Игнорирует кеширование страниц с параметрами GET запроса
453+ if ( event . request . indexOf ( '.html?' ) > - 1 || event . request . indexOf ( '.js?' ) > - 1 ) {
454+ return new Response ( fetch ( event . request ) )
455+ }
456+
462457 event . respondWith (
463458 cacheStrategyImpl ( {
464459 cacheKey : dynamicCacheName ,
0 commit comments