是否有可以缓存的最大图像数量?

时间:2013-10-12 13:18:42

标签: javascript jquery image

我的服务器上有700帧/ 352x288大小9kbs的图像。我想将它们渲染为浏览器上的视频剪辑。我正在使用JQueryAjax来获取这些图像并返回一个<img>的数组,以便通过计时器一个接一个地加载。我发现当我尝试缓存所有700个图像时,我得到一个未指定的服务器错误。我已将缓存减少到250个有效的图像。我的问题是这种类型的缓存是否有限制,是否取决于浏览器,图像大小?

我问这个是因为为了解决我的250最大问题,我会在图像显示后立即动态更新缓存。但如果它依赖于PC /客户端浏览器的限制,这可能会失败。

感谢。

我现有的代码:

HTML

<a href="#" title="Play Motion Clip from Beginning">
<img alt="Play Motion" src="../Images/play_green_controls.png" style="border-style: none; width: 32px; height: 32px; background-color: #000000; cursor: pointer;"
            id="btnPlay" />
</a>
<div id="divImage" >
hello andy
</div>

使用Javascript:

<script type="text/javascript">
    var cache = [];
    var cacheImage = document.createElement('img');
    var interval = 100;
    var _total = 0;

    $("#btnPlay").click(function () {
        $.ajax({
            type: "POST",
            url: "Default3.aspx/GetClips",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                cache = [];
                 _total = 0;
                $.each(msg.d, function () {
                    var cacheImage = document.createElement('img');
                    cacheImage.src = this['Text'];
                    cache[_total] = cacheImage;
                    _total++;
                }
                );
                setInterval('swapImages()', interval);
            },
            error: function (msg) {
                alert(msg.d);
            }
        });
    });
    var div = document.getElementById('divImage');
    var _index = 0;
    function swapImages() {

        if (_index < _total) {              
            if (_index > 0) {
                div.removeChild(cache[_index - 1]);
            }               
            div.appendChild(cache[_index]);
        }
        else {
            interval = 0;
        }
        _index++;
        if (_index  == _total)
        {
            div.removeChild(cache[_index - 1]);
            _index = 0;
            div.appendChild(cache[_index]);
        }
    }

代码背后:

[WebMethod]
public static ArrayList GetClips()
{
    ArrayList _arr = new ArrayList();
    int _max = 250;  //seems to be safe
    string[] _files = Directory.GetFiles(@"C:\Cloud\Catalogues\000EC902F17F\2\2013\10\6\10\f1fe61da-4684-48ed-a503-4a5586ece9c8","*.jpg"); //731
       for (int _index = 0; _index < _files.Length; _index++)
    {
        string _file = _files[_index];
        string[] _bits = _file.Split('\\');
        string _url = "Portal/Catalogues/000EC902F17F/2/2013/10/6/10/f1fe61da-4684-48ed-a503-4a5586ece9c8/" + _bits[10];
        ListItem _item = new ListItem();
        _item.Text = _url;
        _arr.Add(_item);
        if (_index == _max - 1)
        {
            break;
        }
    }
    return _arr;
}

0 个答案:

没有答案