Skip to content

Instantly share code, notes, and snippets.

@jolantis
Forked from PaulKinlan/prefetchbuilder.js
Created October 5, 2015 10:14
Show Gist options
  • Save jolantis/aab2f7269af4ebe69cf8 to your computer and use it in GitHub Desktop.
Save jolantis/aab2f7269af4ebe69cf8 to your computer and use it in GitHub Desktop.
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