我正在研究大量使用JavaScript和Ajax來提供所需功能的客戶端Web應用程序。Internet Explorer 9中的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
}
};
您需要將我們鏈接到代碼或發佈儘可能多的相關內容,以便我們瞭解爲什麼會發生這種情況。 – 2012-04-23 10:07:39
我更新瞭解釋並添加了詳細說明XMLHttppRequest使用的代碼 – saracaen 2012-04-23 12:49:25
按下F-12打開NET選項卡並觀察XHR流量這將幫助您找到延遲 – 2012-04-23 13:22:59