You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Georg Henzler (JIRA)" <ji...@apache.org> on 2019/05/15 20:17:00 UTC

[jira] [Updated] (SLING-8283) httpGet in system/sling.js uses deprecated main thread blocking code

     [ https://issues.apache.org/jira/browse/SLING-8283?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Georg Henzler updated SLING-8283:
---------------------------------
    Summary: httpGet in system/sling.js uses deprecated main thread blocking code  (was: httpGet in system/sling.js uses depricated main thread blocking code)

> httpGet in system/sling.js uses deprecated main thread blocking code
> --------------------------------------------------------------------
>
>                 Key: SLING-8283
>                 URL: https://issues.apache.org/jira/browse/SLING-8283
>             Project: Sling
>          Issue Type: Improvement
>          Components: Best practices, Servlets
>            Reporter: Ruben Reusser
>            Assignee: Robert Munteanu
>            Priority: Major
>             Fix For: Servlets Post 2.3.30
>
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> 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/.|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
>  
> {code:java}
> /**
>  * 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;
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)