Skip to content

Commit ff0b3e3

Browse files
committed
update service worker to better handle non cacheables/ad codes
1 parent d42e06e commit ff0b3e3

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

static/sw.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const BLACKLIST = [
1616
"monu.delivery",
1717
"www.google-analytics.com",
1818
"cognito-identity.us-west-2.amazonaws.com",
19-
"dynamodb.us-west-2.amazonaws.com"
19+
"dynamodb.us-west-2.amazonaws.com",
20+
"googletagmanager.com"
2021
// Note: removed amazonaws.com from blacklist since you have AWS domains in servers.txt
2122
];
2223

@@ -308,21 +309,21 @@ function getFileType(url) {
308309
}
309310

310311
// Main fetch event handler
311-
self.addEventListener('fetch', event => {
312+
self.addEventListener('fetch',async event => {
312313
// Only handle GET requests
313314
if (event.request.method !== 'GET') return;
314315

315316
const request = event.request;
317+
const isCacheable = await isCacheableRequest(request);
316318

319+
if (!isCacheable) {
320+
// Let non-cacheable requests pass through
321+
return;
322+
}
317323
event.respondWith(
318324
(async () => {
319325
// Check if request is cacheable
320-
const isCacheable = await isCacheableRequest(request);
321326

322-
if (!isCacheable) {
323-
// Let non-cacheable requests pass through
324-
return fetch(request);
325-
}
326327

327328
const url = new URL(request.url);
328329
const fileType = getFileType(url);

0 commit comments

Comments
 (0)