Skip to content

Instantly share code, notes, and snippets.

@countzero
Last active November 18, 2021 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save countzero/2a4ee330923add5015c8dd74d6facc80 to your computer and use it in GitHub Desktop.
Save countzero/2a4ee330923add5015c8dd74d6facc80 to your computer and use it in GitHub Desktop.
Example on how to load a deferred JavaScript bundle
alert('WOW!');
<!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