Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Synchronous Ajax calls made by Granite I18N library

Avatar

Level 1

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.

  1. Is there any particular reason for a synchronous call?
  2. And how do we prevent the Deprecated warning messages from appearing on the console?

Version : AEM 6.1+

2 Replies

Avatar

Level 1

Got a response from Adobe team after a ticket was opened for this issue:

The warning should be ignored

The synchronous ajax call is there by design. There are some plans to fix this by loading the file via a synchronous script tag include instead.  That would both avoid the error and optimize performance.  However, that enhancement won't be included in AEM until a future version such as AEM 6.5 as it has already been decided that it won't be included in AEM 6.4 (next year).

FYI

The warning was not causing any issue for us but we wanted to confirm if it was appearing because of any customization we made.