Synchronous XMLHttpRequest on the main thread is deprecated

匿名 (未验证) 提交于 2019-12-03 02:49:01

问题:

Why has this message suddenly started to appear in the Firefox console?

I'm using JQuery 1.7.1.

What in my app could I be doing that has caused this message to start appearing?

回答1:

Using jQuery to append a script tag to the document will cause it to load the script with async:false and trigger this warning.

As in:

var script = $(""); script.attr("src", player.basepath + "whatever.js"); $(document.body).append(script);


回答2:

You have code performing synchronous XHR/Ajax, i.e. Ajax requests that block until they are completed.

When using jQuery, you'd do so by specifying async: false in the settings object of jQuery.ajax().

The solution is to refactor any of your code doing synchronous requests, i.e. kill all instances of jQuery.ajax({async: false}) and helper functions, as well as xhr.open(..., false), include code in third-party libraries you may use. Also, since jQuery 1.7.1 is rather old by standards of the web, I'm not sure if that jQuery version still does internal sync requests in certain cases, you'll have to check for that as well and upgrade jQuery if so.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!