Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save djD-REK/07d86e495bc772133907b63317c3ea56 to your computer and use it in GitHub Desktop.
Save djD-REK/07d86e495bc772133907b63317c3ea56 to your computer and use it in GitHub Desktop.
// <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
const loadScript = async (url) => {
const response = await fetch(url)
const script = await response.text()
Function(script)
}
const scriptUrl = "https://code.jquery.com/jquery-3.5.0.js"
loadScript(scriptUrl)
// Use jQuery:
$("div").css("border", "3px dotted orange")
@Omsteker
Copy link

It looks to me that the code « Function(script) » will not execute.
You can make it a Self-Invoking Functions « (Function(script))() »

https://scriptverse.academy/tutorials/js-self-invoking-functions.html

@DoctorDerek
Copy link

Great point @Omsteker ! It's missing that extra pair of parentheses, one key difference from eval.

I should probably split the whole eval / Function discussion into another article, because it's off topic compared to using appendChild

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment