0

I'm fetching a file using getScript:

    $.getScript("android/android.js")   

and the I cache that file in a cache manifest:

/android/android.js

When i Try to load the page cached, I get a "Get" error.

Himmators
  • 14,278
  • 36
  • 132
  • 223
  • Did you try the way described in the `jQuery.cachedScript` example on http://api.jquery.com/jQuery.getScript/ page? – Petr Vostrel Feb 27 '12 at 23:53

1 Answers1

1

Be default, $.getScript() sets the cache setting to false. This appends a timestamped query parameter to the request URL to ensure that the browser downloads the script each time it is requested. You can override this feature by setting the cache property globally using $.ajaxSetup():

$.ajaxSetup({
  cache: true
});

Alternatively, you could define a new method that uses the more flexible $.ajax() method.

From jQuery's documentation on getScript()

derekaug
  • 2,145
  • 1
  • 17
  • 17
  • 1
    Hmm... doesn't seem to be honoring the `cache: true` for me as it is still appending the query string to prevent caching. I'll try to figure out what's up. – derekaug Feb 15 '12 at 23:51
  • Works for me :) Thanks! – Aleks G Oct 05 '15 at 22:16
  • WARNING: This will enable caching for every ajax call, not just your script call. Instead, replacing `$.getScript` with an `$.ajax` call is the way to go. – Doug S Oct 30 '15 at 06:56