Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,300
    Thanks
    10
    Thanked 586 Times in 567 Posts

    prevent ajax cache?

    is there a way to prevent caching of ajax calls using request headers?

    this is for a library, so i cannot append a timeStamp or make any modifications to the server, or do a post. those are all the suggestions i could find...

    i've found a way to encourage caching using If-Modified-Since, but no way to prevent it.

    any ideas?
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by rnd me View Post
    is there a way to prevent caching of ajax calls using request headers?

    this is for a library, so i cannot append a timeStamp or make any modifications to the server, or do a post. those are all the suggestions i could find...

    i've found a way to encourage caching using If-Modified-Since, but no way to prevent it.

    any ideas?
    pragma no-cache ?,


    best regards

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,300
    Thanks
    10
    Thanked 586 Times in 567 Posts

    Lightbulb

    thanks for the link.

    turns out i was using if-modified wrong, and firebug was lying about the cache.

    this was been a real PITA to figure out, and i am surprised it's not better known.


    this is how to not get a cache in an ajax call for anyone wondering:

    Code:
    function IO(U, V) {
        var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
        X.open('GET', U, false);
     X.setRequestHeader('If-Modified-Since', 'Sat, 29 Oct 1994 19:43:31 GMT');
        X.send(V ? V : '');
    return X.status;
    }
    i can't trust firebug for some reason, but i can time a sync transfer:

    with the red line commented, you can pull a page in ~20ms.
    trace: [21, 20, 20, 21, 21, 21, 21, 20, 21, 21]


    with the red line as is, the performance drops significantly as the data re-transfers.
    trace:[109, 63, 64, 64, 61, 61, 59, 61, 61, 61]
    (the first one here is erroneous because the connection had timed out)

    i also noticed that my router shows a lot more bits coming through when run as is, as compared to being run with the red line commented...


    Thus, I am fairly certain this works, but if anyone can make it not work, please share!
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •