Skip to content

Instantly share code, notes, and snippets.

@parkerproject
Created October 24, 2021 20:17
Show Gist options
  • Save parkerproject/a8b1d673177e707d2871a7a5abc31e37 to your computer and use it in GitHub Desktop.
Save parkerproject/a8b1d673177e707d2871a7a5abc31e37 to your computer and use it in GitHub Desktop.
// Self invoking function
(function(w, d, link, script, p) {
window.onload = function() {
// Load css
var css = "https://cd.example.com/widget.css";
// Load js
var js = "https://cd.example.com/widget.js";
link = d.createElement("link");
link.rel = "stylesheet";
link.href = css;
// Appending stylesheet in the head tag
d.getElementsByTagName("head")[0].appendChild(link);
script = d.createElement("script");
script.async = 1;
script.src = js;
// Adding the script in the script tag
p = d.getElementsByTagName("script")[0];
p.parentNode.insertBefore(script, p);
};
})(window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment