Hi all,
I would really appreciate any input on the following scenario.
On our website, we are seeing the following warning on browser console when a page loads :
“[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help, check https://xhr.spec.whatwg.org/.”
I realized that this is because in one of our JS files we are making a call to Granite.I18n.get(“<string to be translated>“);
The above call in turn places a call to the base Granite library code, a snippet of which is pasted below:
self.getDictionary = function(locale) {
locale = locale || self.getLocale();
if (!dicts[locale]) {
pseudoTranslations = (locale.indexOf(self.PSEUDO_LANGUAGE) == 0);
try {
var response = $.ajax(getDictionaryUrl(locale), {
async: false,
dataType: "json"
});
dicts[locale] = $.parseJSON(response.responseText)
} catch (e) {}
if (!dicts[locale]) {
dicts[locale] = {}
}
}
return dicts[locale]
}
;
self.get = function(text, snippets, note) {
var dict, newText, lookupText;
dict = self.getDictionary();
lookupText = pseudoTranslations ? self.PSEUDO_PATTERN_KEY : note ? text + " ((" + note + "))" : text;
if (dict) {
newText = dict[lookupText]
}
if (!newText) {
newText = text
}
if (pseudoTranslations) {
newText = newText.replace("{string}", text).replace("{comment}", note ? note : "")
}
return util.patchText(newText, snippets)
}
As you can see, a synchronous Ajax call is being placed.
- Is there any particular reason for a synchronous call?
- And how do we prevent the Deprecated warning messages from appearing on the console?
Version : AEM 6.1+