Polymer – skip loading webcomponents.js on Chrome

With polymer, it can help just a little to skip loading the webcomponents.js script, which is the polyfills on a complient browser, like chrome..

To do this, change the following in your index.html from:

<script src="/bower_components/webcomponentsjs/webcomponents.js"></script>

To:

<script>  
if('registerElement' in document
&& 'createShadowRoot' in HTMLElement.prototype
&& 'import' in document.createElement('link')
&& 'content' in document.createElement('template')) {
// we are using browser with WC support YAY!!
console.log("YOU ARE USING A FULLY HTML5 COMPLIANT BROWSER");
} else {
document.write('<script src="/bower_components/webcomponentsjs/webcomponents.js"></script>');
console.log("YOU ARE NOT USING A FULLY HTML5 COMPLIANT BROWSER");
}
</script>

Leave a Reply

Your email address will not be published. Required fields are marked *