tjb
tjb

Reputation: 11728

Are Dynamically Loaded Files Cached by the Browser?

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?

Upvotes: 4

Views: 974

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

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);

Upvotes: 4

Related Questions