What Is The Difference Between `htmlimports.whenready` And `window.addeventlistener('webcomponentsready', Function(e) {`
What is the difference between HTMLImports.whenReady and window.addEventListener('WebComponentsReady', function(e) {? Polymer's official documentation says: 'To define an element
Solution 1:
They are almost * the same: both are triggered at the same time.
So you can choose your favourite flavor between callback
and Event
.
Nota Bene: if, for some reasons, you reference the CustomElement.js
polyfill alone (i.e. without the HTMLImports.js
feature), only the WebComponentsReady
event will be thrown.
(I prefer to use the Event Handler
because in the first case you need to be sure the HTMLImports
is defined, and because it is the only documented API here)
*: Of course they are different! The difference is stated in the quoted definitions.
- The latter is waiting for the Custom Elements to be instanciated. It is triggered by
CustomElement.js
polyfill. - The first is waiting only for the Imports to be loaded and parsed. It is called by
HTMLImports.js
polyfill, just after{HTMLImportsLoaded}
has been sent.
However in normal situation, because Custom Elements are instanciated as soon as they are registered, the 2 events will happen one after the other.
Chronological order
<link rel=import>.onload()
,{HTMLImportsLoaded}
event,HTMLImports.whenReady()
{WebComponentsReady}
event
More here.
Post a Comment for "What Is The Difference Between `htmlimports.whenready` And `window.addeventlistener('webcomponentsready', Function(e) {`"