我目前正在加快所做的ajax請求。基本上該網站通過實時過濾工作。所以當用戶點擊表單元素時,數據會相應加載。這一切都非常好,但並不像我想要的那樣快。JQuery AJAX緩存與PHP文件
我的AJAX看起來有點像這樣(我顯然省略了變量):
$.ajax({
type: "GET",
url: 'URL NAME',
data: {
'Var1': Var1,
'Var2': Var2
},
cache:true, // Set cache to TRUE
success: function(data) {
$('.content').html(data);
},
complete: function() {
$("#loading_ajax").hide();
$('.content').fadeIn();
}
}).error(function (event, jqXHR, ajaxSettings, thrownError) {
$('.content').html("<h2>Could not retrieve data</h2>");
//alert('[event.status:' + event.status + '], [event:' + event + '], [jqXHR:' + jqXHR + '], [ajaxSettings:' + ajaxSettings + '], [thrownError:' + thrownError + '])');
});
在其中得到請求數據的另一面,在PHP中的第一行是這樣的:
$seconds = 86400;
header("Cache-Control: private, max-age=$seconds");
header("Expires: ".gmdate('r', time()+$seconds));
然後,我進入Firebug檢查緩存,它似乎並沒有工作。 螢火蟲打印出以下幾點:
第二個屏幕有顯示該請求已實際放緩(我重複了一遍,看看是否緩存會提高它並沒有區別)。有任何想法嗎?謝謝。
檢查[快的東西然後ajax發送/接收數據](http://stackoverflow.com/questions/12814624/online-gaming-or-something-faster-then-ajax-for-sending-receiving-data/12814665#12814665) –
你可以嗎還發布請求標頭.. –
如果您從服務器配置而不是單個文件控制緩存策略,會不會更好? http://httpd.apache.org/docs/2.2/caching.html –