I am trying to imported some javascript files from some code hosts.
$.when(
$.getScript('http://pingzi.googlecode.com/svn-history/r30/branches/wangqi/web/jquery.window.min.js'),
$.getScript('http://mottie.github.com/tablesorter/js/jquery.tablesorter.js'),
$.getScript('http://tconnell.com/samples/scroller/lib/jquery.tablesorter.scroller.js'),
$.getScript('http://code.highcharts.com/stock/highstock.js'),
$.Deferred(
function(deferred) {
$(deferred.resolve);
}
)
).done(function() {
// my function goes here....
});
When I try to call these URLs to import js files, the URLs will append ?_=1344036242417 and then I could not actually get to the script file I want.
i.e.
"NetworkError: 404 Not Found - http://pingzi.googlecode.com/svn-history/r30/branches/wangqi/web/jquery.window.min.js?_=1344036242417"
Any one have ideas how to bypass this problem? Thank you in advance.
That’s because caching in ajax is turned off by default in jQuery, to turn it on and remove the querystring do :
but that could also affect other ajax calls that you don’t want to cache, there’s a lot more on this in the docs for getScript, and there’s even a little how-to on creating a cached getScript function called cachedScript.
You can also enable caching in $.getScript by redefining the function with a new option to turn the cache on/off by passing true or false :