From d16447a82ac45aa9fa99ac1b457e9cc6a84d9b42 Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Mon, 6 Mar 2017 14:43:58 -0800 Subject: [PATCH] Cleanup README Fix es5 loader by checking for the correct name :P --- README.md | 4 +--- webcomponents-es5-loader.js | 5 +++-- webcomponents-loader.js | 5 +++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index df49646..c107edf 100644 --- a/README.md +++ b/README.md @@ -63,9 +63,7 @@ elements, etc.). Here's an example: ## `webcomponents-es5-loader.js` -Due to the requirement that Custom Elements be ES6 classes (https://html.spec.whatwg.org/multipage/scripting.html#custom-element-conformance), it may make sense to precompile your elements down to ES5 for wider consumption. -However, this will conflict with the presence of native Custom Elements in browsers that support them. -For these scenarios, use the `webcomponents-es5-loader.js` file to use the Custom Elements native compatibility shim where needed. +Custom Elements must be ES6 classes (https://html.spec.whatwg.org/multipage/scripting.html#custom-element-conformance). Since most projects need to support a wide range of browsers that don't necessary support ES6, it may make sense to compile your project to ES5. However, ES5-style custom element classes will not work with native Custom Elements because ES5-style classes cannot properly extend ES6 classes, like `HTMLElement`. ## Browser Support diff --git a/webcomponents-es5-loader.js b/webcomponents-es5-loader.js index 32f3825..7141ecf 100644 --- a/webcomponents-es5-loader.js +++ b/webcomponents-es5-loader.js @@ -10,6 +10,7 @@ (function() { 'use strict'; + var name = 'webcomponents-es5-loader.js'; // Feature detect which polyfill needs to be imported. var polyfills = []; if (!('import' in document.createElement('link'))) { @@ -35,11 +36,11 @@ } if (polyfills.length) { - var script = document.querySelector('script[src*="webcomponents-loader.js"]'); + var script = document.querySelector('script[src*="' + name + '"]'); var newScript = document.createElement('script'); // Load it from the right place. var replacement = 'webcomponents-' + polyfills.join('-') + '.js'; - var url = script.src.replace('webcomponents-loader.js', replacement); + var url = script.src.replace(name, replacement); newScript.src = url; document.head.appendChild(newScript); } else { diff --git a/webcomponents-loader.js b/webcomponents-loader.js index 3f86ea5..999cfdc 100644 --- a/webcomponents-loader.js +++ b/webcomponents-loader.js @@ -10,6 +10,7 @@ (function() { 'use strict'; + var name = 'webcomponents-loader.js'; // Feature detect which polyfill needs to be imported. var polyfills = []; if (!('import' in document.createElement('link'))) { @@ -33,11 +34,11 @@ } if (polyfills.length) { - var script = document.querySelector('script[src*="webcomponents-loader.js"]'); + var script = document.querySelector('script[src*="' + name +'"]'); var newScript = document.createElement('script'); // Load it from the right place. var replacement = 'webcomponents-' + polyfills.join('-') + '.js'; - var url = script.src.replace('webcomponents-loader.js', replacement); + var url = script.src.replace(name, replacement); newScript.src = url; document.head.appendChild(newScript); } else {