Skip to content

Instantly share code, notes, and snippets.

@kswedberg
Forked from mathiasbynens/jquery.loadasync.js
Created January 26, 2012 19:03
Show Gist options
  • Save kswedberg/1684397 to your computer and use it in GitHub Desktop.
Save kswedberg/1684397 to your computer and use it in GitHub Desktop.
Use jQuery to load scripts asynchronously
// Load scripts asynchronously
jQuery.loadScript = function(url, options) {
// Don't use $.getScript since it disables caching
options = $.extend(options || {}, {
dataType: 'script',
cache: true,
url: url
};
jQuery.ajax(options);
};
@mathiasbynens
Copy link

A bit simpler:

    options = $.extend({
            'dataType': 'script',
            'cache': true,
            'url': url
        }, options);

Will work fine if options is undefined. What do you think?

@kswedberg
Copy link
Author

true, but my way enforces the dataType and cache.

@mathiasbynens
Copy link

Oh, hadn’t thought of it that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment