Skip to content

Commit

Permalink
disable service worker image cache for avatars (#465)
Browse files Browse the repository at this point in the history
fixes #464
  • Loading branch information
nolanlawson authored Aug 22, 2018
1 parent 2956e20 commit d30ffc6
Showing 1 changed file with 0 additions and 23 deletions.
23 changes: 0 additions & 23 deletions templates/service-worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const timestamp = '__timestamp__'
const ASSETS = `assets_${timestamp}`
const WEBPACK_ASSETS = `webpack_assets_${timestamp}`
const ON_DEMAND = `ondemand_${timestamp}`

// `assets` is an array of everything in the `assets` directory
const assets = __assets__
Expand Down Expand Up @@ -36,7 +35,6 @@ self.addEventListener('activate', event => {
// delete old asset/ondemand caches
for (let key of keys) {
if (key !== ASSETS &&
key !== ON_DEMAND &&
!key.startsWith('webpack_assets_')) {
await caches.delete(key)
}
Expand All @@ -63,10 +61,6 @@ self.addEventListener('activate', event => {
})())
})

const ON_DEMAND_PATHS = [
'/system/accounts/avatars'
]

self.addEventListener('fetch', event => {
const req = event.request
const url = new URL(req.url)
Expand All @@ -93,23 +87,6 @@ self.addEventListener('fetch', event => {
}
}

// For these GET requests, go cache-first
if (req.method === 'GET' &&
ON_DEMAND_PATHS.some(pattern => url.pathname.startsWith(pattern))) {
let cache = await caches.open(ON_DEMAND)
let response = await cache.match(req)
if (response) {
// update asynchronously
fetch(req).then(response => {
cache.put(req, response.clone())
})
return response
}
response = await fetch(req)
cache.put(req, response.clone())
return response
}

// for everything else, go network-only
return fetch(req)
})())
Expand Down

0 comments on commit d30ffc6

Please sign in to comment.