sling-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Georg Henzler (JIRA)" <j...@apache.org>
Subject [jira] [Closed] (SLING-8283) httpGet in system/sling.js uses deprecated main thread blocking code
Date Mon, 20 May 2019 06:54:00 GMT

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

Georg Henzler closed SLING-8283.
--------------------------------
    Assignee:     (was: Robert Munteanu)

> 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
>            Priority: Major
>             Fix For: Starter Content 1.0.4, 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)

Mime
View raw message