dynamic-resource-hints
Advanced tools
Comparing version 0.0.6 to 0.0.7
16
index.js
var makeHint = function makeHint(href, rel, as, crossorigin, type) { | ||
var link = document.createElement("link"); | ||
var existingLink = document.querySelector("link[href=\"" + href + "\"]"); | ||
if (existingLink) { | ||
if (existingLink.getAttribute(rel)) return; | ||
} | ||
link.setAttribute("rel", rel); | ||
@@ -14,3 +20,3 @@ link.setAttribute("href", href); | ||
var hasBeenPrefetched = []; | ||
var allowedRels = ['preload', 'prefetch', 'prerender', 'subresource', 'prefetch', 'preconnect', 'dns-prefetch']; | ||
var allowedRels = ['preload', 'prerender', 'subresource', 'prefetch', 'preconnect', 'dns-prefetch']; | ||
@@ -40,11 +46,5 @@ function preloadResource(href, rel, as, crossorigin, type) { | ||
if (!hasBeenPrerendered.includes(href)) { | ||
hasBeenPrerendered.push(makeHint(href, rel, as, crossorigin, type)); | ||
} | ||
if (!hasBeenPrefetched.includes(href)) { | ||
hasBeenPrefetched.push(makeHint(href, rel, as, crossorigin, type)); | ||
} | ||
makeHint(href, rel, as, crossorigin, type); | ||
} | ||
module.exports = preloadResource; |
{ | ||
"name": "dynamic-resource-hints", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Dynamically add preload browser hints at runtime", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
4683
38