Reputation: 26352
I get some scripts asynchronously on my login page:
$.when(
$.getScript("/Scripts/View/scroll-sneak.js"),
$.getScript("/Scripts/kendo/kendo.custom.min.js"),
$.Deferred(function (deferred) {
$(deferred.resolve);
})
).done(function (res1, res2) {
if (res1[1] == "success") {
}
if (res2[1] == "success") {
}
alert('all script loaded...');
});
I have two queries here:
Alternate solutions are welcome.
Upvotes: 0
Views: 65
Reputation: 5493
Answer to your first question is set cache true. Jquery documentation page also mentions a way
jQuery.cachedScript = function( url, options ) {
// Allow user to set any option except for dataType, cache, and url
options = $.extend( options || {}, {
dataType: "script",
cache: true,
url: url
});
// Use $.ajax() since it is more flexible than $.getScript
// Return the jqXHR object so we can chain callbacks
return jQuery.ajax( options );
};
// Usage
$.cachedScript( "ajax/test.js" ).done(function( script, textStatus ) {
console.log( textStatus );
});
For your second question: Please clarify more, what you want to achive?
Upvotes: 1