0
$('#in-view-contents').load("/browse/".concat(selectedId), function(responseData){
    var contentsLabelEl = document.getElementById("refined-contents-container");
    contentsLabelEl.style.display = "block";
    var arrayOfReloadScripts = ["/js/rateable.js", "/js/siteWide.js", "/js/search/searchEvents.js"];
    reloadScripts(arrayOfReloadScripts);
});

and reloadScripts just iterates though the array and calls this function:

function reload_js(src) {
    $('script[src="' + src + '"]').remove();
    $('<script>').attr('src', src).appendTo('head');
}

Does this cause jquery to make an synchronous call like explained in this SO answer? If not how do I rerun a set of functions that I need to run once the html/server response is loaded?

EDIT: Here is the code for reloadScripts:

var reloadScripts = function(array){
    var len = array.length;
    for (var i = 0; i < len; i++){
        reload_js(array[i]);
    }
}
Community
  • 1
  • 1
user3494047
  • 1,643
  • 4
  • 31
  • 61
  • We need to see the logic of `reloadScripts()` to help you. Presumably you've set `async: false` in there, which is the problem. – Rory McCrossan Mar 28 '17 at 15:27
  • 1
    No, using .load doesn't cause this warning. I wouldn't expect appending scripts to the page to cause this warning either. – Kevin B Mar 28 '17 at 15:33
  • @RoryMcCrossan I added the code for reloadScripts(). I never set the async property anywhere, at least not that I know of. – user3494047 Mar 28 '17 at 15:40
  • 1
    What version of jquery are you using? there was a bug related to this that was fixed in 3.x. You could work around said bug by not using jquery to create/append those scripts. – Kevin B Mar 28 '17 at 15:45
  • @KevinB I see. I'm using 2.2.4. I'll try that/updating jquery and see what happens – user3494047 Mar 28 '17 at 15:56
  • @KevinB, I tried updating to 3.2 but the warning still came up. So I went back to 2.2 and tried using regular JS (no jquery) and it solved it. If you make it answer, I'll accept it. Otherwise I'll post one. – user3494047 Mar 28 '17 at 16:54
  • Thanks for posting this question. I upped your question to get rid of that -1. It's a valuable question to post for those still using 2.x (because it works). I'd like to upgrade but that isn't always possible in production codebases and available timelines. I should add we get this problem on Chrome loading stock jQuery 2.2.4. We're not doing any special reload stuff like you are. – Shovas Apr 25 '18 at 17:11

1 Answers1

0

I removed the jquery code in reload_js and changed it to the following:

function reload_js(src) {
    var originalScript = document.querySelector('script[src="' + src + '"]');
    var parentEl = originalScript.parentNode;
    parentEl.removeChild(originalScript);
    // $('script[src="' + src + '"]').remove();
    var newScript = document.createElement('script');
    newScript.src = src;
    parentEl.appendChild(newScript);
    // $('<script>').attr('src', src).appendTo('head');
}

I did this because in the comments it was mentioned that this might be a bug in jquery. After doing this, the warning went away.

user3494047
  • 1,643
  • 4
  • 31
  • 61