Skip to content

Instantly share code, notes, and snippets.

@anandanand84
Forked from ebidel/app.html
Created May 20, 2016 19:32
Show Gist options
  • Save anandanand84/9de762c0cde7c9d45dc660c57e2db69b to your computer and use it in GitHub Desktop.
Save anandanand84/9de762c0cde7c9d45dc660c57e2db69b to your computer and use it in GitHub Desktop.

Revisions

  1. @ebidel ebidel revised this gist Jul 29, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -32,8 +32,8 @@ function finishLazyLoading() {
    var link = document.querySelector('#bundle');

    // 5. Go if the async Import loaded quickly. Otherwise wait for it.
    // crbug.com/504944 - readyState never goes to complete in Chrome
    // crbug.com/505279 - Resource Timing API is also not viable atm.
    // crbug.com/504944 - readyState never goes to complete until Chrome 46.
    // crbug.com/505279 - Resource Timing API is not available until Chrome 46.
    if (link.import && link.import.readyState === 'complete') {
    onImportLoaded();
    } else {
  2. @ebidel ebidel revised this gist Jul 1, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion app.html
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@
    to town pre-fetching resources, etc. -->
    <link rel="import" id="bundle" href="elements.html" async>
    </head>
    <!-- 2. Don't use <body class="unresolved">. It's a simple FOUC solution, but hides
    <!-- 2. Don't use <body unresolved>. It's a simple FOUC solution, but hides
    the page until imports and Polymer are loaded. Intead, control FOUC manually with
    a splash screen. -->
    <body class="loading">
  3. @ebidel ebidel revised this gist Jun 29, 2015. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -17,8 +17,7 @@ if (!webComponentsSupported) {

    function finishLazyLoading() {
    // (Optional) Use native Shadow DOM if it's available in the browser.
    window.Polymer = window.Polymer || {};
    window.Polymer.dom = 'shadow';
    window.Polymer = window.Polymer || {dom: 'shadow'};

    // 6. Fade splash screen, then remove.
    var onImportLoaded = function() {
  4. @ebidel ebidel revised this gist Jun 29, 2015. 1 changed file with 10 additions and 16 deletions.
    26 changes: 10 additions & 16 deletions app.html
    Original file line number Diff line number Diff line change
    @@ -20,25 +20,19 @@
    }
    </style>

    <!--
    1. Async HTML Imports do not block rending. Benefit of keeping it declarative
    (instead of dynamically loading it later in JS) is that the parser can go
    to town pre-fetching resources, etc.
    -->
    <!-- 1. Async HTML Imports do not block rending. Benefit of keeping it declarative
    (instead of dynamically loading it later in JS) is that the parser can go
    to town pre-fetching resources, etc. -->
    <link rel="import" id="bundle" href="elements.html" async>
    </head>
    <!--
    2. Don't use <body class="unresolved">. It's a simple FOUC solution, but hides
    the page until imports and Polymer are loaded. Intead, control FOUC manually with
    a splash screen.
    -->
    <!-- 2. Don't use <body class="unresolved">. It's a simple FOUC solution, but hides
    the page until imports and Polymer are loaded. Intead, control FOUC manually with
    a splash screen. -->
    <body class="loading">
    <!--
    3. Light weight splash screen is outside of Polymer/imports and styled by
    the main page. 1st paint is fast, even on polyfilled browsers. Alternatively,
    one could create an "app shell" and style the page's un-upgraded elements
    similar to their final upgraded version.
    -->
    <!-- 3. Light weight splash screen is outside of Polymer/imports and styled by
    the main page. 1st paint is fast, even on polyfilled browsers. Alternatively,
    one could create an "app shell" and style the page's un-upgraded elements
    similar to their final upgraded version. -->
    <div id="splash"></div>

    <!-- Elements wait on the page and are upgraded when elements.html loads. -->
  5. @ebidel ebidel revised this gist Jun 29, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion app.html
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@
    </head>
    <!--
    2. Don't use <body class="unresolved">. It's a simple FOUC solution, but hides
    the page until everything is loaded. We'll instead control FOUC manually with
    the page until imports and Polymer are loaded. Intead, control FOUC manually with
    a splash screen.
    -->
    <body class="loading">
  6. @ebidel ebidel revised this gist Jun 29, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -32,9 +32,9 @@ function finishLazyLoading() {

    var link = document.querySelector('#bundle');

    // 5. There's a chance the async HTML Import loaded quickly, otherwise wait
    // for it to load.
    // TODO: crbug.com/504944 - readyState never goes to "complete" in Chrome.
    // 5. Go if the async Import loaded quickly. Otherwise wait for it.
    // crbug.com/504944 - readyState never goes to complete in Chrome
    // crbug.com/505279 - Resource Timing API is also not viable atm.
    if (link.import && link.import.readyState === 'complete') {
    onImportLoaded();
    } else {
  7. @ebidel ebidel renamed this gist Jun 27, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. @ebidel ebidel revised this gist Jun 27, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion app.js
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ if (!webComponentsSupported) {
    script.async = true;
    script.src = '/bower_components/webcomponentsjs/webcomponents-lite.min.js';
    script.onload = finishLazyLoading;
    document.head.appendChild(wcPoly);
    document.head.appendChild(script);
    } else {
    finishLazyLoading();
    }
  9. @ebidel ebidel created this gist Jun 27, 2015.
    43 changes: 43 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    // 4. Conditionally load the webcomponents polyfill if needed by the browser.
    // This feature detect will need to change over time as browsers implement
    // different features.
    var webComponentsSupported = ('registerElement' in document
    && 'import' in document.createElement('link')
    && 'content' in document.createElement('template'));

    if (!webComponentsSupported) {
    var script = document.createElement('script');
    script.async = true;
    script.src = '/bower_components/webcomponentsjs/webcomponents-lite.min.js';
    script.onload = finishLazyLoading;
    document.head.appendChild(wcPoly);
    } else {
    finishLazyLoading();
    }

    function finishLazyLoading() {
    // (Optional) Use native Shadow DOM if it's available in the browser.
    window.Polymer = window.Polymer || {};
    window.Polymer.dom = 'shadow';

    // 6. Fade splash screen, then remove.
    var onImportLoaded = function() {
    var loadEl = document.getElementById('splash');
    loadEl.addEventListener('transitionend', loadEl.remove);

    document.body.classList.remove('loading');

    // App is visible and ready to load some data!
    };

    var link = document.querySelector('#bundle');

    // 5. There's a chance the async HTML Import loaded quickly, otherwise wait
    // for it to load.
    // TODO: crbug.com/504944 - readyState never goes to "complete" in Chrome.
    if (link.import && link.import.readyState === 'complete') {
    onImportLoaded();
    } else {
    link.addEventListener('load', onImportLoaded);
    }
    }
    51 changes: 51 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    <!DOCTYPE html>
    <html>
    <head>
    <style>
    body.loading #splash {
    opacity: 1;
    }
    #splash {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    transition: opacity 300ms cubic-bezier(0,0,0.2,1);
    opacity: 0;
    will-change: opacity;
    z-index: 1;
    background: url(...) no-repeat;
    background-color: #E53935;
    }
    </style>

    <!--
    1. Async HTML Imports do not block rending. Benefit of keeping it declarative
    (instead of dynamically loading it later in JS) is that the parser can go
    to town pre-fetching resources, etc.
    -->
    <link rel="import" id="bundle" href="elements.html" async>
    </head>
    <!--
    2. Don't use <body class="unresolved">. It's a simple FOUC solution, but hides
    the page until everything is loaded. We'll instead control FOUC manually with
    a splash screen.
    -->
    <body class="loading">
    <!--
    3. Light weight splash screen is outside of Polymer/imports and styled by
    the main page. 1st paint is fast, even on polyfilled browsers. Alternatively,
    one could create an "app shell" and style the page's un-upgraded elements
    similar to their final upgraded version.
    -->
    <div id="splash"></div>

    <!-- Elements wait on the page and are upgraded when elements.html loads. -->
    <paper-drawer-panel>
    ...
    </paper-drawer-panel>

    <script src="app.js" async></script>
    </body>
    </html>