Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Caching in IE

We have a site here using a Wufoo form and the Wufoo jQuery API.

We're pulling data from the API, sorting it and then displaying it on the page. When we submit the form with a number higher than the current top 10, it should update in real-time on the right hand side, as the form redirects back to itself. It does this, but not in IE. Instead, there appears to be an unwanted lag between when the form is submitted and when the new data is displayed. Closing the browser and reopening the page seems to work, but that's not helpful.

Here is the jQuery we're using:

<script>
    $.wufooAPI.getEntries({
        "callback"   : processEntries,             
        "formHash"   : "x7x1x7",                   
        "sortID"   : "Field3",                   
        "sortDirection"   : "DESC",
    });
    function processEntries(data) {
        $.each(data.Entries.slice(0, 10), function(entriesIndex, entriesObject) {
            // Make sure this entry has all the required bits
            if (entriesObject.Field1 && entriesObject.Field3) {
                $("#attendeeTemplate").tmpl(entriesObject).appendTo("#people ul");  
            }
        });
    };

</script>

And here is the template code:

            <script id="attendeeTemplate" type="text/x-jquery-tmpl">
                <li>
                    <h4>${Field1}</h4>
                    ${Field3} minutes
                </li>
            </script>

It works perfectly in all browsers except IE8 and 9, when it looks like it's caching the data and not pulling the request from the server.

Is there any way to stop caching of jQuery in IE?

like image 610
Nietzsche Avatar asked May 13 '12 00:05

Nietzsche


1 Answers

An easy way is to cheat and salt your request url with a timestamp (but that's a bit clumsy). You can switch off caching for ajax requests:

$.ajaxSetup ({
    // Disable caching of AJAX responses
    cache: false
});

MSDN has a page about cache-avoidance in IE http://support.microsoft.com/kb/234067.

like image 78
web_bod Avatar answered Oct 14 '22 07:10

web_bod