Skip to content

Instantly share code, notes, and snippets.

@nuc
Last active July 2, 2018 14:03
Show Gist options
  • Save nuc/02a11d72fa96bc57df9cfe35e51934f1 to your computer and use it in GitHub Desktop.
Save nuc/02a11d72fa96bc57df9cfe35e51934f1 to your computer and use it in GitHub Desktop.
<!--
Browser support: partial
Success rate: 30%-90% depending on browser
Can prefetch HTML: yes
-->
<link rel="prefetch" href="index.html" />
function getTimeToInteractive() {
const domInteractive = window.performance.timing.domInteractive;
const requestStart = window.performance.timing.requestStart;
return domInteractive - requestStart;
}
/*
* returns: [
* {
* name: 'haha.js',
* duration: 12313,
* transferSize: [bytes || 0 if served from cache]
* }]
*/
function getResourceEntries() {
return window.performance.getEntriesByType('resource') || [];
}
/*
* Browser support: full
* Success rate: > 95%
* Can prefetch HTML: no
*/
function prefetchResource(resourceURL) {
const xhrRequest = new XMLHttpRequest();
xhrRequest.open('GET', resourceURL, true);
xhrRequest.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment