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'