Reputation: 29935
I have a javascript script that I want to load synchronously, but the URL of the script is determined by the value of a cookie. For example:
<script src="/js/[user-id-from-cookie].js">
This script has to load in the <head>
of my HTML document and must be run synchronously (it has to block the main thread while it is downloaded and executed).
How can I use javascript to:
I need to do this in pure javascript, no frameworks like jQuery etc.
Thanks!
Upvotes: 0
Views: 215
Reputation: 10604
You can use document.write
to load scripts synchronously.
But use it this way may cause some lag, I'd like to offer some alternatives.
Upvotes: 1