Is it possible to monitor file downloads? For example -

var style_css = 'css/syle.css'; style_css.onload(function() { console.log('css loaded'); }); 
 var js = 'js/java.js'; js.onload(function() { console.log('js loaded'); }); 

Is there something like that?
Maybe in php , js , html , ajax or some other language?

    2 answers 2

     load('style.css'); load('script.js'); 
     function load(url) { if(url.match(/.js/)) { content = document.createElement('script'); content.type = 'text/javascript'; content.src = url; } if(url.match(/.css/)) { content = document.createElement('link'); content.rel = 'stylesheet'; content.type = 'text/css'; content.href = url; } document.body.appendChild(content); content.onerror = function() { console.log(url, 'not exist'); } content.onload = function() { console.log(url, 'loaded'); } } 

     <link rel='stylesheet' type='text/css' href='style.css' onload="console.log(this.href, 'loaded');"> <script type='text/javascript' src='script.js' onload="console.log(this.src, 'loaded');"></script> 
    • Yes, for dynamic loading is also a great option - Vasily Barbashev
    • Also a good option. Thank! - Brave_Lime
    • Excuse me, which option is better? The first, it seems, is adaptive ... Or does it seem to me? Thank. - Brave_Lime
    • @Brave_Lime, if you only need to report in the console, then it is easier to display the event in the html. <script onload='console.log(this)'> - Mr. Black
    • @Doofy Well, the task is in: "When loading a specific file, a change in html markup occurs (using jQuery )" ... I can do <script onLoad="some_function();" src="https:.."></script> <script onLoad="some_function();" src="https:.."></script> No? - Brave_Lime

    Can!

     <script onLoad="alert(this.src + ' загружен');" src="https://code.jquery.com/jquery-2.2.4.min.js"></script> 

    You can write some function or perform it, then:

     <script> function onLoadHandler(obj) { alert(obj.src + ' загружен'); } </script> <script onLoad="onLoadHandler(this);" src="https://code.jquery.com/jquery-2.2.4.min.js"></script> 

    • Cool, thank you very much !! - Brave_Lime