-
-
Save jolantis/aab2f7269af4ebe69cf8 to your computer and use it in GitHub Desktop.
Code to return link rel=dnsprefetch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var requests = window.performance.getEntries(); | |
var hosts = {}; | |
var output = ""; | |
for(var requestIdx = 0; requestIdx < requests.length; requestIdx++) { | |
var request = requests[requestIdx]; | |
var origin = new URL(request.name).origin; | |
hosts[origin] = 1; | |
} | |
for(var key in hosts) { | |
output += "<link rel=\"dns-prefetch\" href=\"" + key + "\">\n"; | |
} | |
alert(output); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment