Skip to content

Instantly share code, notes, and snippets.

@naderio
Last active August 29, 2015 14:24
Show Gist options
  • Save naderio/7a6c7fc6c2852564c101 to your computer and use it in GitHub Desktop.
Save naderio/7a6c7fc6c2852564c101 to your computer and use it in GitHub Desktop.
Conditionally load WebComponents polyfill for use with Polymer, fire `WebComponentsReady` anyway
<script>
if ('registerElement' in document
&& 'createShadowRoot' in HTMLElement.prototype
&& 'import' in document.createElement('link')
&& 'content' in document.createElement('template')) {
(function () {
function ready() {
setTimeout(function () {
document.dispatchEvent(new CustomEvent('WebComponentsReady', {
bubbles: true
}));
});
}
if (document.readyState === 'complete' || document.readyState === 'interactive') {
ready();
} else {
window.addEventListener('DOMContentLoaded', ready);
}
})();
} else {
document.write('<script src="bower_components\/webcomponentsjs\/webcomponents.min.js"><\/script>');
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment