I have some javascript code in the HEAD that sets a cookie. Later at the bottom of the page I load another javascript file. This file is served by a dynamic back-end page that uses the cookie to determine what to return.
A problem occurs in Firefox because it uses speculative parsing: it loads the javascript file at the end of the page before the javascript in the HEAD has executed. Since the cookie has not yet been set when the second javascript file is loaded, the back-end page does not receive the cookie value.
Is there any way to prevent Firefox from loading the second javascript file too soon?
If you want a script to be fetched over HTTP after another script has run (instead of when the browser finds the script in the DOM it is creating by parsing HTML) then generate the second
script
element using JS/DOM instead of putting it in the HTML.