Javascript 为什么我的背景图像被延迟?

Javascript 为什么我的背景图像被延迟?,javascript,sencha-touch,sencha-touch-2,Javascript,Sencha Touch,Sencha Touch 2,我正在使用Sencha Touch 2.1.1中的一个项目模板来显示一个状态、一张图片和一些关于用户的详细信息,作为列表中的一个项目。当我加载页面时,我看到加载所有图片时都有延迟,除了第一张图片,它的时间大约与JSONP调用获取状态的时间一样长。你可以看到 我的模板非常简单: itemTpl: [ "<div class='listView people'>", " <tpl if='workforceID != undefined'

我正在使用Sencha Touch 2.1.1中的一个项目模板来显示一个状态、一张图片和一些关于用户的详细信息,作为列表中的一个项目。当我加载页面时,我看到加载所有图片时都有延迟,除了第一张图片,它的时间大约与JSONP调用获取状态的时间一样长。你可以看到

我的模板非常简单:

    itemTpl: [
        "<div class='listView people'>",
        "   <tpl if='workforceID != undefined'>",
        "       <tpl if='workforceID == \"phind\" || workforceID == \"NULL\"'>",
        "           <div class='avatar notFound user'></div>",
        "       <tpl else>",
        "     <tpl if='presence != undefined && presence != null && getAvailability(presence) == \"Available\"'><div class='avatar status available' style='background-image: url(https://services.xxx.com/emppics/{workforceID}.jpg);'><span></span></div>",
          "          <tpl elseif='presence != undefined && presence != null && getAvailability(presence) == \"Busy\"'><div class='avatar status busy' style='background-image: url(https://services.xxx.com/emppics/{workforceID}.jpg);'><span></span></div>",
          "          <tpl elseif='presence != undefined && presence != null && getAvailability(presence) == \"Away\"'><div class='avatar status away' style='background-image: url(https://services.xxx.com/emppics/{workforceID}.jpg);'><span></span></div>",
          "          <tpl elseif='presence != undefined && presence != null && getAvailability(presence) == \"Unavailable\"'><div class='avatar status unavailable' style='background-image: url(https://services.xxx.com/emppics/{workforceID}.jpg);'><span><em></em></span></div>",
          "          <tpl elseif='presence != undefined && presence != null && getAvailability(presence) == \"Offline\"'><div class='avatar status offline' style='background-image: url(https://services.xxx.com/emppics/{workforceID}.jpg);'><span></span></div>",
          "          <tpl elseif='presence != undefined && presence != null && getAvailability(presence) == \"Do Not Disturb\"'><div class='avatar status dnd' style='background-image: url(https://services.xxx.com/emppics/{workforceID}.jpg);''><span><em></em></span></div>",
          "     <tpl else>",
          "         <div class='avatar status offline' style='background-image: url(https://services.xxx.com/emppics/{workforceID}.jpg);'><span><em></em></span></div>",
          "     </tpl>",
        "       </tpl>",
        "   </tpl>",
        "   <ul class='data'>",
        "      <li><h3><strong>{fullName}</strong></h3></li>",
        "      <tpl if='title != undefined && title != null'><li><span class=\"userTitle\">{title}</span></li></tpl>",
        "      <tpl if='roomNumber != undefined && roomNumber != null && roomNumber != \"\"'><li><span class=\"userOffice\">Office: {roomNumber}</span></li></tpl>",
        "   </ul>",
        "</div>"
    ]

如果我调用JSONP,当然会立即加载图片,所以我不确定为什么JSONP调用会阻止加载背景图像。浏览器不应该不考虑进行JSONP调用所需的时间而获取图像吗?

我找到的最佳解决方案不是使用CSS,而是使用
标记。现在我的代码变成:


我不能肯定地说,但是JSONP的工作方式是插入一个脚本标记来完成请求。在脚本标记完成之前,浏览器可能会阻止任何图像加载。
function getUserPresence (record) {
    var email = record.get('mail');
    if (email && email !== 'NULL') { // Need to actually check for text value of NULL :(
        // Get Users' Presence
        Ext.data.JsonP.request({
            url: Global.presenceUrl + encodeURIComponent(email),
            callbackKey: 'callback',
            disableCaching: false,
            success: function (result, request) {
                if (result) {
                    var presence = result.Availability;
                    record.set('presence', presence);
                }
            },
            failure: function () {
                console.log('Unable to obtain Lync presence at this time');
            },
            timeout: 15000, //if no response something is wrong and just cancel
            scope: this
        });
    }
}
<div class='avatar status available'><img onerror='imgError(this)' src='https://services.xxx.com/pics/{id}.jpg'/></div>
function imgError (image) {
    image.onerror = function () {
        this.parent().addClass('user');
    }
    image.src = "/resources/img/user.png";
    return true;
}