I have a question about reloading JavaScript files. I develop web pages front-ends and do a lot of coding in JS. Every time when I want to check an application's flow is correct (or do some debugging) I have to hit F5 key to reload whole page and it's scripts, and I have to wait. Waiting time depends on page's weight and sometimes I get impatient. Therefore I wonder if there is any way to reload only changed script file *.js
? or maybe there is some plugin for Chrome to reload chosen script? It could be a very handy way to ease development. Thank you for replies.
this one uses jQuery, it is here for example:
var scs=$('script[type*=javascript]');
var scsl = scs.length;
var scsi = 0;
var o = [];
var oi = 0;
var ol = 0;
var s = '';
var fws = 0;
var sws = 0;
var v = {};
function i1(){
fws = window.setInterval(function(){
v = $(scs[scsi]);
s = v.attr('src');
if(typeof s!='undefined' && s.indexOf('http')==-1 && s.indexOf('index')==-1){
console.log([scsl,scsi,s]);
o.push({src:s});
v.remove();
}
if(scsi==scsl){
console.log(o);
window.clearInterval(fws);
ol = o.length;
i2();
}
else{
scsi++;
}
},800);
}
function i2(){
sws=window.setInterval(function(){
v = o[oi];
sc = $('<script>').attr({type:'text/javascript',src:v.src+'?t='+(new Date().getTime())});
console.log([ol,oi,v.src]);
$('head').append(sc);
if(oi==ol-1){
window.clearInterval(sws);
}
else{
oi++;
}
},800);
}
i1();