Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use jQuery to load scripts asynchronously
// Load scripts asynchronously
jQuery.loadAsync = function(url, callback) {
// Don't use $.getScript since it disables caching
jQuery.ajax({
'url': url,
'dataType': 'script',
'cache': true,
'success': callback || jQuery.noop
});
};
@davidhund

This comment has been minimized.

Copy link

davidhund commented Jan 26, 2012

Good tip. This is basically what $.getScript() does, but with the cache AJAX option, right? I was surprised to find that $.getScript() does not accept this option itself :/

@mathiasbynens

This comment has been minimized.

Copy link
Owner Author

mathiasbynens commented Jan 26, 2012

Yeah, I’ve pinged @kswedberg about it — he’ll be adding it to the documentation page for $.getScript soon.

@oriadam

This comment has been minimized.

Copy link

oriadam commented Jul 5, 2017

$.getScript support caching when using the options object signature like this:

$.getScript({
    url: "foo.js",
    cache: true
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.