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:
- Read the value of a cookie
- Download and execute the script synchronously
I need to do this in pure javascript, no frameworks like jQuery etc.
Thanks!
document.write. But why you need it to load synchronously?