Last active
November 18, 2021 13:24
-
-
Save countzero/2a4ee330923add5015c8dd74d6facc80 to your computer and use it in GitHub Desktop.
Example on how to load a deferred JavaScript bundle
This file contains 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
alert('WOW!'); |
This file contains 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
<!doctype html> | |
<head> | |
<meta charset="utf-8"> | |
<title>load deferred bundle</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<script type="text/javascript"> | |
document.addEventListener('DOMContentLoaded', function(event) { | |
function loadDeferredBundle() { | |
var scriptDOMElement = document.createElement('script'); | |
scriptDOMElement.src = './bundle.js'; | |
document.head.appendChild(scriptDOMElement); | |
} | |
document.getElementById('consent-button').addEventListener('click', loadDeferredBundle); | |
}); | |
</script> | |
</head> | |
<body> | |
<button id='consent-button'>CONSENT</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment