I want to reload and re-execute some javascript resources after some event happens. I looked up how to do this and found this SO question to be helpful. It says to remove the javascript resource and then create a new script tag referencing the same resource and append it to the head or body.
I tried it and it works.
I am using this code:
var reloadScripts = function(){
var len = LOCALBROWSEVARIABLES.filesToReload.length;
for (var i = 0; i < len; i++){
reload_js(LOCALBROWSEVARIABLES.filesToReload[i]);
}
}
function reload_js(src) {
$('script[src="' + src + '"]').remove();
$('<script>').attr('src', src).appendTo('head');
}
This code works for me. I can tell it works because I can see the outcome of the javascript functions that are being re run. But one of my files is not working as expected and I want to debug it. The problem is that when I put break points anywhere in the files that are being reloaded, they work when I first open the page, but not when they are reloaded. So I am not able to debug these reloaded scripts. Does anyone know why debugging/break points is not working when the scripts are being reloaded?
Aucun commentaire:
Enregistrer un commentaire