Browse Source

Don't preload URLs with query strings, unless attribute present in body

Alexandre Dieulot 6 years ago
parent
commit
a40409c794
2 changed files with 6 additions and 0 deletions
  1. 5 0
      instantpage.js
  2. 1 0
      test/header.html

+ 5 - 0
instantpage.js

@@ -6,6 +6,7 @@ let lastTouchTimestamp
 
 const prefetcher = document.createElement('link')
 const isSupported = prefetcher.relList && prefetcher.relList.supports && prefetcher.relList.supports('prefetch')
+const allowQueryString = 'instantAllowQueryString' in document.body.dataset
 
 if (isSupported) {
   prefetcher.rel = 'prefetch'
@@ -97,6 +98,10 @@ function isPreloadable(linkElement) {
     return
   }
 
+  if (!allowQueryString && urlObject.search) {
+    return
+  }
+
   if (urlObject.pathname + urlObject.search == location.pathname + location.search && urlObject.hash) {
     return
   }

+ 1 - 0
test/header.html

@@ -29,3 +29,4 @@ a:active {
   background: hsla(0, 0%, 0%, .25);
 }
 </style>
+<body data-instant-allow-query-string>