-
Notifications
You must be signed in to change notification settings - Fork 70
Правит ошибки в обработке события fetch в Service Worker #1346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -434,24 +434,31 @@ self.addEventListener('message', async (event) => { | |
| }) | ||
|
|
||
| self.addEventListener('fetch', async (event) => { | ||
| const url = new URL(event.request.url) | ||
|
|
||
| // Игнорирует запросы на другие домены | ||
| if (!event.request.startsWith(self.location.origin) && event.request.method === 'POST') { | ||
| return new Response(fetch(event.request)) | ||
| if (url.origin !== self.location.origin) { | ||
| return | ||
| } | ||
|
|
||
| // Игнорирует обработку не GET-запросов | ||
| if (event.request.method !== 'GET') { | ||
| return | ||
| } | ||
|
|
||
| // Игнорирует кеширование Service Worker | ||
| if (event.request.endsWith('sw.js')) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вообще, такая ситуация возможна только если кто-то сделает внутри основного кода |
||
| return new Response(fetch(event.request)) | ||
| return | ||
| } | ||
|
|
||
| // Игнорирует кеширование манифеста | ||
| if (event.request.endsWith('manifest.json')) { | ||
| return new Response(fetch(event.request)) | ||
| return | ||
| } | ||
|
|
||
| // Игнорирует кеширование страниц с параметрами GET запроса | ||
| if (event.request.indexOf('.html?') > -1 || event.request.indexOf('.js?') > -1) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут можно было бы заменить такую проверку на что-то типа |
||
| return new Response(fetch(event.request)) | ||
| return | ||
| } | ||
|
|
||
| event.respondWith( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Чтобы Service Worker не обрабатывал запрос, достаточно досрочно вернуть
undefined.