Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code to return link rel=dnsprefetch
(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
You can’t perform that action at this time.