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.

Revisions

  1. nuc revised this gist Jul 2, 2018. No changes.
  2. nuc revised this gist May 3, 2018. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion thingies.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,14 @@ function getTimeToInteractive() {

    return domInteractive - requestStart;
    }

    /*
    * returns: [
    * {
    * name: 'haha.js',
    * duration: 12313,
    * transferSize: [bytes || 0 if served from cache]
    * }]
    */
    function getResourceEntries() {
    return window.performance.getEntriesByType('resource') || [];
    }
  3. nuc revised this gist May 3, 2018. 2 changed files with 10 additions and 2 deletions.
    6 changes: 5 additions & 1 deletion index.html
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,6 @@
    <!-- can be used for html documents -->
    <!--
    Browser support: partial
    Success rate: 30%-90% depending on browser
    Can prefetch HTML: yes
    -->
    <link rel="prefetch" href="index.html" />
    6 changes: 5 additions & 1 deletion thingies.js
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,11 @@ function getResourceEntries() {
    return window.performance.getEntriesByType('resource') || [];
    }

    // can be used for JS & CSS Assets
    /*
    * Browser support: full
    * Success rate: > 95%
    * Can prefetch HTML: no
    */
    function prefetchResource(resourceURL) {
    const xhrRequest = new XMLHttpRequest();
    xhrRequest.open('GET', resourceURL, true);
  4. nuc revised this gist May 3, 2018. 2 changed files with 2 additions and 0 deletions.
    1 change: 1 addition & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -1 +1,2 @@
    <!-- can be used for html documents -->
    <link rel="prefetch" href="index.html" />
    1 change: 1 addition & 0 deletions thingies.js
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,7 @@ function getResourceEntries() {
    return window.performance.getEntriesByType('resource') || [];
    }

    // can be used for JS & CSS Assets
    function prefetchResource(resourceURL) {
    const xhrRequest = new XMLHttpRequest();
    xhrRequest.open('GET', resourceURL, true);
  5. nuc revised this gist May 3, 2018. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions thingies.js
    Original file line number Diff line number Diff line change
    @@ -7,4 +7,10 @@ function getTimeToInteractive() {

    function getResourceEntries() {
    return window.performance.getEntriesByType('resource') || [];
    }

    function prefetchResource(resourceURL) {
    const xhrRequest = new XMLHttpRequest();
    xhrRequest.open('GET', resourceURL, true);
    xhrRequest.send();
    }
  6. nuc revised this gist May 3, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    <link rel="prefetch" href="index.html" />
  7. nuc revised this gist May 3, 2018. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions thingies.js
    Original file line number Diff line number Diff line change
    @@ -3,4 +3,8 @@ function getTimeToInteractive() {
    const requestStart = window.performance.timing.requestStart;

    return domInteractive - requestStart;
    }

    function getResourceEntries() {
    return window.performance.getEntriesByType('resource') || [];
    }
  8. nuc created this gist May 3, 2018.
    6 changes: 6 additions & 0 deletions thingies.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    function getTimeToInteractive() {
    const domInteractive = window.performance.timing.domInteractive;
    const requestStart = window.performance.timing.requestStart;

    return domInteractive - requestStart;
    }