Last active
March 6, 2020 16:00
-
-
Save timoxley/7451206 to your computer and use it in GitHub Desktop.
dynamic html imports hack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // currently polymer only only loads html imports | |
| // on first page load. After the first pass over the document, | |
| // adding any additional <link> elements will have no effect. | |
| // This adds a link to src, and forces polymer to load it | |
| function load(src, fn) { | |
| var link = document.createElement('link') | |
| link.setAttribute('rel', 'import') | |
| link.setAttribute('href', src) | |
| document.body.appendChild(link) | |
| HTMLImports.importer.load(document, function() { | |
| HTMLImports.parser.parseLink(link) | |
| // CustomElements polyfill needs to process the dynamic imports for definitions. | |
| CustomElements.parser.parse(link.import.content) | |
| fn(null, link.import.content) | |
| }) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added "CustomElements parsing" call courtesy of @wkruse https://gist.github.com/wkruse/7481517