Internet Explorer 9 中的 Ajax 刷新后速度变慢

Ajax in Internet Explorer 9 slow after refresh

本文关键字:速度 刷新 Ajax Explorer 中的 Internet      更新时间:2023-09-26

我正在开发一个客户端Web应用程序,该应用程序大量使用JavaScript和Ajax来提供所需的功能。

对于大多数浏览器(Chrome,Firefox等)来说,这不是问题,但是在Internet Explorer中,性能是一个主要问题。

最初加载页面只需不到一秒钟的时间,即使在Internet Explorer上也是如此。但是在刷新页面时,加载和显示页面可能需要 1 到 20 秒。

由于

应用程序分为多个文件,因此很难发布代码。我只能解释预期的行为。

应用程序初始化两个内容容器,一个用于静态内容,一个用于动态内容。这些内容容器中的每一个都是通过 Ajax 填充的,并通过 innerHTML 属性影响 DOM 元素。

第一次构建页面需要不到一秒钟的时间。后续刷新需要更长的时间。

页面

的初始加载和页面的刷新之间发生了哪些变化来解释这种巨大的性能下降?卸载页面时是否需要取消初始化某些内容?

Communication.request = function (method, target, async, data, callback) {
    var types = ['string', 'string', 'boolean', 'null', 'null'];                // Parameter types
    if (data) {                                                                 // Data was provided
        types[3] = 'string';                                                    // Data must be a string
    }
    if (callback) {                                                             // Callback was provided
        types[4] = 'function';                                                  // Callback must be a function
    }
    if (Utils.hasParams(arguments, types)) {                                    // All the required parameters were provided and of the right type
        var request = new XMLHttpRequest();                                     // Create a new request
        request.open(method, target, async);                                    // Open the request
        if (callback) {                                                         // Callback was provided
            request.handleCallback(callback);                                   // Register the callback
        }
        if (data) {                                                             // Data was provided
            var contentType = 'application/x-www-form-urlencoded';              // Prepare the content type
            request.setRequestHeader('Content-Type', contentType);              // Add a content type request header
        }
        request.send(data);                                                     // Send the request
    }
};

该问题似乎与并发连接数有关。根据 Web 服务器的连接/类型,这在 Internet Explorer 中限制为 2 或 4 个并发连接。

将连接数固定为 2 后,问题不再出现。其他浏览器似乎有更高的限制,尽管为了以防万一,我将其限制为 4 个。

此外,并发消息的数量是任何给定时间正在进行的消息数量。这以前是无限的,这让Internet Explorer非常难过:-(