History

Update service worker to more accurately detect 'internal' url's

Jasper van Merle committed 7 years ago

Commit ad8cd231 parent 32028371 file · +4 −1Browse files

Unified · Split

views/service-worker.js.erb+4−1
@@ -48,7 +48,10 @@ self.addEventListener('fetch', event => { · 47 unmodified lines
48 48
49 <%# Attempt to return the index page from the cache if the user is visiting a url like devdocs.io/offline or devdocs.io/javascript/global_objects/array/find %>49 <%# Attempt to return the index page from the cache if the user is visiting a url like devdocs.io/offline or devdocs.io/javascript/global_objects/array/find %>
50 <%# The index page will make sure the correct documentation or a proper offline page is shown %>50 <%# The index page will make sure the correct documentation or a proper offline page is shown %>
51 if (url.origin === location.origin && !url.pathname.replace(/~([0-9.])+/, '').includes('.')) {51 const pathname = url.pathname;
52 const filename = pathname.substr(1 + pathname.lastIndexOf('/')).split(/\#|\?/g)[0];
53
54 if (url.origin === location.origin && !filename.includes('.')) {
52 const cachedIndex = await caches.match('/');55 const cachedIndex = await caches.match('/');
53 if (cachedIndex) return cachedIndex;56 if (cachedIndex) return cachedIndex;
54 }57 }