I am conditionally loading JavaScript and it seems like it doesn't run when I run it normally. But when I run the same with debug mode with breakpoint. It works fine. Could anyone please let me know what is the issue?
I have this JavaScript in header of the html.
<script> var sc = document.createElement('script'); sc.type = 'text/javascript'; if(server == "a"){ sc.src = "sample.js"; } else{ sr.src = "test.js"; } document.getElementsByTagName('head')[0].appendChild(sc); </script> <script type='text/javascript'> sample.getSomething(); </script> This sample object is an object in sample.js/test.js and gets loaded only in debug mode, otherwise it is 'not available'
alert()calls to ensure the script is running?sr.srcconsole.log(stmt)and it prints the stmt. When I said it doesn't work, I mean I feel script is not being loaded to head.server?