| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (function() { | 5 (function() { |
| 6 "use strict"; | 6 "use strict"; |
| 7 | 7 |
| 8 var START_LOADING_DELAY = 1000; | 8 var RESOURCES_TO_LOAD = [ |
| 9 | 9 'chrome://resources/polymer/v1_0/iron-icons/iron-icons.html', |
| 10 function doLazyLoad() { | 10 'chrome://resources/polymer/v1_0/paper-button/paper-button.html' |
| 11 function lazyLoadUrl(url) { | 11 ]; |
| 12 var link = document.createElement('link'); | 12 /* const */ var IDLE_TIMEOUT_MS = 200; |
| 13 link.rel = 'import'; | |
| 14 link.href = url; | |
| 15 document.body.appendChild(link); | |
| 16 } | |
| 17 | |
| 18 lazyLoadUrl('chrome://resources/polymer/v1_0/iron-icons/iron-icons.html'); | |
| 19 lazyLoadUrl( | |
| 20 'chrome://resources/polymer/v1_0/paper-button/paper-button.html'); | |
| 21 } | |
| 22 | 13 |
| 23 window.addEventListener('load', function() { | 14 window.addEventListener('load', function() { |
| 24 setTimeout(doLazyLoad, START_LOADING_DELAY); | 15 // The user pod template gets cloned shortly after the load event to make |
| 16 // the actual user pods. It then takes a few update cycles to style these |
| 17 // elements. Loading polymer will block the DOM, so we try to load polymer |
| 18 // after the user pods have been cloned and styled. |
| 19 requestIdleCallback(function() { |
| 20 for (var resourceUrl of RESOURCES_TO_LOAD) { |
| 21 var link = document.createElement('link'); |
| 22 link.rel = 'import'; |
| 23 link.href = resourceUrl; |
| 24 document.head.appendChild(link); |
| 25 } |
| 26 }, { timeout: IDLE_TIMEOUT_MS }); |
| 25 }); | 27 }); |
| 26 })(); | 28 })(); |
| OLD | NEW |