Last active
May 4, 2019 13:50
-
-
Save illvart/4b74e8e76a47655905acb3325ee0e7bb to your computer and use it in GitHub Desktop.
Era Material: append script by JSON - The Keyword | Google: add support module and nomodule
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
| <div id="base-scripts" data-scripts='[ | |
| { | |
| "url": "/static/main.mjs", | |
| "options": { | |
| "async": false, | |
| "defer": false, | |
| "type": "module" | |
| "nomodule": false | |
| } | |
| }, | |
| { | |
| "url": "/static/main.js", | |
| "options": { | |
| "async": true, | |
| "defer": false, | |
| "type": "text/javascript", | |
| "nomodule": true | |
| } | |
| } | |
| ]'></div> | |
| <div id="extra-scripts" data-scripts=''></div> | |
| <script> | |
| var base_scripts = document.querySelector("#base-scripts").getAttribute("data-scripts"); | |
| base_scripts = JSON.parse(base_scripts); | |
| var extra_scripts = document.querySelector("#extra-scripts").getAttribute("data-scripts"); | |
| if (extra_scripts) { | |
| extra_scripts = JSON.parse(extra_scripts); | |
| } else { | |
| extra_scripts = []; | |
| } | |
| var scripts = base_scripts.concat(extra_scripts); | |
| scripts.forEach(function(scriptObj) { | |
| var s = document.createElement("script"); | |
| s.async = scriptObj.options.async; | |
| s.defer = scriptObj.options.defer; | |
| s.type = scriptObj.options.type; | |
| s.noModule = scriptObj.options.nomodule; | |
| s.src = scriptObj.url; | |
| document.head.appendChild(s); | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment