jQuery Caching in IE
Asked Answered
G

1

7

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?

Goshorn answered 13/5, 2012 at 0:19 Comment(2)
Have you tried seeing if anything is being stored in the jquery data, api.jquery.com/jQuery.removeDataBuckbuckaroo
When you say it looks like it's caching, does this mean you see (in IE Dev Tools) a request go out and the response is status 200 (from cache) or 304 Not Modified? Is the server sending Expires or max-age headers? Is the client sending max-stale? Are there any caches or proxies between browser and web server?Steed
C
20

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.

Carvel answered 16/5, 2012 at 22:32 Comment(1)
How did you get on with the caching problem?Carvel

© 2022 - 2024 — McMap. All rights reserved.