Created
March 21, 2017 01:36
-
-
Save mcnamee/1daa78e7bf6271bc2107ec83444d67f5 to your computer and use it in GitHub Desktop.
Prefetch URL on Hover
This file contains hidden or 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($) { | |
// Which links should we prefetch? | |
var $linkElements = $(".menu-item a"); | |
$linkElements.on("hover", function() { | |
var link = $(this).attr("href"), | |
prerenderLink = $("#prerenderLink"); | |
if (prerenderLink.length) { | |
if (prerenderLink.attr("href") === link) return; | |
prerenderLink.attr("href", link); | |
} else { | |
$('<link id="prerenderLink" rel="prefetch prerender" href="' + link + '" />').appendTo("body"); | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment