3

I'm currently trying to speed up the ajax requests made. 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({
        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:

$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 printed out the following:

First Firebug Image

Second Firebug Image

enter image description here

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.

30secondstosam
  • 4,476
  • 4
  • 28
  • 33
  • check [something faster then ajax for sending/receiving data](http://stackoverflow.com/questions/12814624/online-gaming-or-something-faster-then-ajax-for-sending-receiving-data/12814665#12814665) – NullPoiиteя Dec 12 '12 at 10:43
  • Could you also post the request headers.. – Kent Pawar Dec 12 '12 at 10:44
  • Wouldn't it be better if you control the cache policy from the server configuration, rather than individual files? http://httpd.apache.org/docs/2.2/caching.html – hyankov Dec 12 '12 at 10:56
  • @KentPawar - Request headers put in – 30secondstosam Dec 12 '12 at 10:58
  • BUMP - any ideas? Anyone!?? I know this is a complex issue so I'm kinda expecting not to get a response but I feel a good response would help so many people out there. – 30secondstosam Dec 12 '12 at 11:33
  • Make sure your headers sent from server arrive to client, for example that they are not overriden later on in your code, or by proxies (if any). – Stan Dec 12 '12 at 13:57
  • Hey did you find out why the header("Cache-Control: private, max-age=$seconds") is not getting set? Seems like your host is overriding the settings for security/bandwidth-saving purposes.. http://palizine.plynt.com/issues/2008Jul/cache-control-attributes/ – Kent Pawar Dec 13 '12 at 08:12
  • Hi @KentPawar - I did not find out. I'm going to have a dig on the server I think. Thanks - I'll drop a message back in here when I find out – 30secondstosam Dec 13 '12 at 14:41
  • Cool. Good luck with that. Generally you could just drop in a mail to the sysadmin support if your site is hosted on a provider – Kent Pawar Dec 13 '12 at 14:44

1 Answers1

0

Optimize your website loading time by compressing files into smaller size.

Add this to your .htaccess file

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

JorisW
  • 128
  • 1
  • 7