Treat html file as failure in emoji cache

This commit is contained in:
tusooa 2023-06-16 23:12:20 -04:00
commit cc4d4ccbeb
No known key found for this signature in database
GPG key ID: 42AEC43D48433C51

View file

@ -193,17 +193,22 @@ self.addEventListener('notificationclick', (event) => {
self.addEventListener('fetch', (event) => {
// Do not mess up with remote things
const isSameOrigin = (new URL(event.request.url)).origin === self.location.origin
const isEmojiSuccessful = (resp) => {
const type = resp.headers.get('Content-Type')
// Backend will revert to index.html if the file does not exist, so text/html for emojis is a failure
return type && !type.includes('text/html')
}
if (shouldCache && event.request.method === 'GET' && isSameOrigin && isNotMedia(event.request)) {
event.respondWith((async () => {
const r = await caches.match(event.request)
if (r) {
if (r && (isEmojiSuccessful(r) || !isEmoji(event.request))) {
return r
}
try {
const response = await fetch(event.request)
if (response.ok && isEmoji(event.request)) {
if (response.ok && isEmojiSuccessful(response) && isEmoji(event.request)) {
const cache = await caches.open(emojiCacheKey)
await cache.put(event.request.clone(), response.clone())
}