I'm adding theme setting to my js application. The application should work also off-line, so I have to check if the remote style file (like http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/jquery/jquery-ui.css
) exists and is reachable, otherwise I set the href
in <link rel="stylesheet">
to point to a local file.
Till now I used the following code, but with jQuery 2.1.3 it output on console a warning:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
elicited at line jquery-2.1.3.js:8556
Well, I could ignore the warning...
url = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/jquery/jquery-ui.css";
$.ajax({url: url,
type: "HEAD",
timeout: 1000,
async: false,
error: function() {url = 'css/jquery-ui.css';}
});
/* modify link statement to use url for href */
Searching for an alternative method, I tried to check if the link statement has loaded the new css after changing its href, something like:
$('#id_of_the_link_stmt').error(function() {
console.log("New url not loaded, reverting to local file")
}).attr('href', url);
but it does not works.
Thanks for suggesting!