浏览代码

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

Jasper van Merle 6 年之前
父节点
当前提交
ad8cd233d7
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      views/service-worker.js.erb

+ 4 - 1
views/service-worker.js.erb

@@ -48,7 +48,10 @@ self.addEventListener('fetch', event => {
 
       <%# 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 %>
       <%# The index page will make sure the correct documentation or a proper offline page is shown  %>
-      if (url.origin === location.origin && !url.pathname.replace(/~([0-9.])+/, '').includes('.')) {
+      const pathname = url.pathname;
+      const filename = pathname.substr(1 + pathname.lastIndexOf('/')).split(/\#|\?/g)[0];
+
+      if (url.origin === location.origin && !filename.includes('.')) {
         const cachedIndex = await caches.match('/');
         if (cachedIndex) return cachedIndex;
       }