Take the tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a javascript file loading via jQuery.getScript on the client and I'm setting cache-control headers with 1hr browser caching on the server side. It looks like IE caches ajax requests and the functions present in the file do not execute in IE. Does setting false in the getScript call override the cache-control headers of 1hr set from the server side?

var jsCache = true;
    if($.browser.msie){
        jsCache = false;
    }
        if(!initialized){

            $.getScript('thatjsfileurl', function() { 
             $("#welcome").pluginInit({
                start:'newPage'
             });  
             initialized = true;
            },jsCache);
        }

Note: There is also Akamai in place, so can't set the browser detection code on the servlet side.

share|improve this question
add comment

2 Answers

Per the jQuery doc for getScript, there is no cache setting argument for the getScript() call so you aren't doing anything with your jsCache variable.

You can add a timestamp number into the URL and bypass any IE caching.

    if(!initialized) {
        $.getScript("thatjsfileurl" + "?now=" + new Date().getTime(), function() { 
            $("#welcome").pluginInit({
               start:'newPage'
            });  
            initialized = true;
        });
    }
share|improve this answer
add comment
up vote 0 down vote accepted

I figured the answered by myself by testing the above code I posted. The server side header variables like cache-control: 1hr etc are overridden by the browser when we set the variable to cache is set to false. Everytime the IE browser fetches a new copy from the server when the cache is set to false.

var jsCache = true;
    if($.browser.msie){
        jsCache = false;
    }
        if(!initialized){

            $.getScript('thatjsfileurl', function() { 
             $("#welcome").pluginInit({
                start:'newPage'
             });  
             initialized = true;
            },jsCache);
        }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.