Skip to content

Instantly share code, notes, and snippets.

@jonmunson
Forked from PaulKinlan/prefetchbuilder.js
Created December 3, 2015 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonmunson/e37d80d1847776e8969b to your computer and use it in GitHub Desktop.
Save jonmunson/e37d80d1847776e8969b 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