Browse Source

Access the potentially preloadable parts of the URL directly on the anchor element, without `new URL`

Alexandre Dieulot 5 years ago
parent
commit
cd148a1404
1 changed files with 5 additions and 7 deletions
  1. 5 7
      instantpage.js

+ 5 - 7
instantpage.js

@@ -95,25 +95,23 @@ function isPreloadable(linkElement) {
     return
   }
 
-  const preloadLocation = new URL(linkElement.href)
-
-  if (!allowExternalLinks && preloadLocation.origin != location.origin && !('instant' in linkElement.dataset)) {
+  if (!allowExternalLinks && linkElement.origin != location.origin && !('instant' in linkElement.dataset)) {
     return
   }
 
-  if (!['http:', 'https:'].includes(preloadLocation.protocol)) {
+  if (!['http:', 'https:'].includes(linkElement.protocol)) {
     return
   }
 
-  if (preloadLocation.protocol == 'http:' && location.protocol == 'https:') {
+  if (linkElement.protocol == 'http:' && location.protocol == 'https:') {
     return
   }
 
-  if (!allowQueryString && preloadLocation.search && !('instant' in linkElement.dataset)) {
+  if (!allowQueryString && linkElement.search && !('instant' in linkElement.dataset)) {
     return
   }
 
-  if (preloadLocation.hash && preloadLocation.pathname + preloadLocation.search == location.pathname + location.search) {
+  if (linkElement.hash && linkElement.pathname + linkElement.search == location.pathname + location.search) {
     return
   }