A modern loader for the web components polyfills.
The official web component polyfills ships with a loader that should be included in your index.html. The challenge with this loader is that also adds language polyfills like Promise
and Symbol
on browsers that require it. At best this leads to duplicate code when already including these polyfills elsewhere in your app. At worst it will conflict and crash your app. For instance, this is a known issue with babel polyfills.
This loader seeks to solve this issue, it only loads the required web component polyfills. Additionally, the loader uses dynamic imports so that it integrates properly with your app's dependency graph. This works nicely when using the usage
option on babel's polyfill transform.
The loader should be called before importing you app:
import loadPolyfills from '@open-wc/polyfills-loader';
loadPolyfills().then(() => import('./my-app.js'));
If your app contains code that doesn't use any of the web component APIs, they can be imported at the same time as the loader:
import loadPolyfills from '@open-wc/polyfills-loader';
import './my-non-web-component-code.js';
loadPolyfills().then(() => import('./my-web-component-code.js'));
The web component polyfill loads:
- Broken CustomEvent on IE11
- HTMLTemplateElement
- CustomElements API
- ShadowDom API
- URL and URLSearchParams
The webcomponent polyfill requires:
- Promise
- Array.from
- Symbol
Make sure the required polyfills are loaded before calling the loader. If you configure babel to load these polyfills on usage, this is done automatically.
<script> export default { mounted() { const editLink = document.querySelector('.edit-link a'); if (editLink) { const url = editLink.href; editLink.href = url.substr(0, url.indexOf('/master/')) + '/master/packages/polyfills-loader/README.md'; } } } </script>