Skip to content

Instantly share code, notes, and snippets.

@freddielore
Created June 28, 2019 02:46
Show Gist options
  • Save freddielore/2a9ed1dfb3dfe0b4a3ef1c341e8a51b0 to your computer and use it in GitHub Desktop.
Save freddielore/2a9ed1dfb3dfe0b4a3ef1c341e8a51b0 to your computer and use it in GitHub Desktop.
[Defer Third Party Scripts] Defer third party scripts #javascript #html #public
<script type="text/javascript">
var app = {
init: function() {
window.addEventListener('scroll', function() {
if (window.__he == undefined) {
app.load();
}
});
window.addEventListener('mousemove', function() {
if (window.__he == undefined) {
app.load();
}
});
},
load: function() {
var script = document.createElement('script');
script.src = '//healthengine.com.au/webplugin/appointments.js';
script.defer = true;
script.setAttribute('data-he-id', 'foo');
script.setAttribute('data-he-button', 'true');
script.setAttribute('data-he-img', 'HE_BOOKNOW_1.png');
document.getElementById('health-engine').appendChild(script);
script.onload = function() {
window['__he'] = true;
}
window['__he'] = true;
}
};
app.init();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment