Last active
March 14, 2018 14:37
-
-
Save ryantownsend/a7039e4a0cbc5fc00ef0deef0d7dca93 to your computer and use it in GitHub Desktop.
JavaScript to prefetch marked links after page load
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
| <script> | |
| function(w, d) { | |
| var prefetchLinks = function() { | |
| d.querySelectorAll("a[href][rel='prefetch']").forEach(function() { | |
| var link = d.createElement('link'); | |
| link.rel = 'prefetch'; | |
| link.href = this.getAttribute('href'); | |
| d.head.appendChild(link); | |
| }); | |
| } | |
| w.addEventListener('load', prefetchLinks); | |
| })(window, document); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment