简体   繁体   English

使用PHP文件进行JQuery AJAX缓存

[英]JQuery AJAX Caching with PHP file

I'm currently trying to speed up the ajax requests made. 我目前正在努力加快所提出的ajax请求。 Basically the site works by live filtering. 基本上该网站通过实时过滤工作。 So when a user clicks on a form element, the data will load accordingly. 因此,当用户单击表单元素时,数据将相应地加载。 This all works fantastically well but it's not as quick as I want it to be. 这一切都运行得非常好,但它并不像我想要的那么快。

My AJAX looks a bit like this (i've obviously omitted the variables): 我的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 + '])');
});

On the other side where the data is getting requested, the first lines in the PHP are this: 在获取数据请求的另一端,PHP中的第一行是:

$seconds = 86400;

header("Cache-Control: private, max-age=$seconds");
header("Expires: ".gmdate('r', time()+$seconds));

I then went into Firebug to check for caching and it didn't seem to work at all. 然后我进入Firebug检查缓存,它似乎根本不起作用。 Firebug printed out the following: Firebug打印出以下内容:

第一个Firebug图像

第二个Firebug图像

在此输入图像描述

The second screenshot there shows that the request had actually slowed down (I repeated it to see if the caching would improve it and it hasn't made a difference). 那里的第二个屏幕截图显示请求实际上已经放慢了速度(我重复它以查看缓存是否会改善它并且它没有任何区别)。 Any ideas? 有任何想法吗? Thanks. 谢谢。

Optimize your website loading time by compressing files into smaller size. 通过将文件压缩为更小的尺寸来优化网站加载时间。

Add this to your .htaccess file 将其添加到.htaccess文件中

AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript application/json AddOutputFilterByType DEFLATE text / text text / html text / plain text / xml text / css application / x-javascript application / javascript application / json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM