4

I have a question that is related to this answer, $.getScript(filename)

Are dynamically loaded files cached by the browser?

If not, how can I force them to be?

0

1 Answer 1

4

It seems that they are not. Proposed workaround is to redefine the function:

$.getScript = function(url, callback, cache) {
    $.ajax({
        type: "GET",
        url: url,
        success: callback,
        dataType: "script",
        cache: cache
    });
};

which could be used like this:

$.getScript('/foo.js', function() { }, true);
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for finding this for me. The jQuery documentation for cache (api.jquery.com/jQuery.ajax) says only that if you set cache to false the browser will not cache. It doesn't say that if you set it to true it will cache...off to do some testing
setting cahce: true/false via .ajaxSetup method also affects the getScript.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.