Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-8283

httpGet in system/sling.js uses deprecated main thread blocking code

    XMLWordPrintableJSON

Details

    Description

      the sling starter homepage throws the following error in the browser console.

      sling.js:75 [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/.

      As the error mentions this is due to the fact that sling is using main thread blocking calls in /system/sling.js - this is generally not recommended anymore as it blocks the ability for a user to interact with the browser

      The problem can easily be solved by using callbacks instead of main thread blocking code. 

      by altering Sling.httpGet to support callbacks this change can be made gradually over time without a break in backwards compatibility

       

      /**
       * HTTP GET XHR Helper
       * @param {String} url The URL
       * @param {Function} optional second parameter for async version of the method.
       *        The callback will get the XHR object, method returns immediately
       * @return the XHR object, use .responseText for the data
       * @type String
       */
      Sling.httpGet = function(url, callback) {
          var httpcon = Sling.getXHR();
          if (httpcon) {
              if(callback) {
                  httpcon.onload = function() { callback(this); };
                  httpcon.open('GET', url);
                  httpcon.send(null);
              } else {
                  httpcon.open('GET', url, false);
                  httpcon.send(null);
                  return httpcon;
              }
          } else {
              return null;
          }
      }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              reusr1 Ruben Reusser
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1.5h
                  1.5h