[ 
https://issues.apache.org/jira/browse/SLING-8283?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16771970#comment-16771970
 ] 

Ruben Reusser commented on SLING-8283:
--------------------------------------

https://github.com/apache/sling-org-apache-sling-servlets-post/pull/4

> httpGet in system/sling.js uses depricated main thread blocking code
> --------------------------------------------------------------------
>
>                 Key: SLING-8283
>                 URL: https://issues.apache.org/jira/browse/SLING-8283
>             Project: Sling
>          Issue Type: Improvement
>          Components: Best practices
>            Reporter: Ruben Reusser
>            Priority: Major
>
> 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)

Reply via email to