I have several Cdns that I would like to load only when I call a particular function, right now I have it in the head but this makes the web slow down and it may be the case that those Cdns are not needed either. I have done it with document.write but it doesn't work.
<script>window.jQuery || document.write('<script src="assets/js/vendor/jquery-slim.min.js"><\/script>')</script>
You can easily upload the script and also run a function when the upload is complete.
You can do this as follows
This will cause a to be inserted
<script>
when loading the windowYou can do it with a function
If you want to insert it during the execution of a function and then delete it, you can save it as a global variable and when the function is executed do a
appendChild
and after the function aremoveChild
We will call the function and after a
timeout
we will make the element disappear from the DOM