get.js revision d0fa6f87745bf4e7c206e531a67f5c433f52e92f
4d6c3c157705c101f044293dd642b62683918dedDav GlassProvides dynamic loading of remote JavaScript and CSS resources.
4d6c3c157705c101f044293dd642b62683918dedDav Glass // -- Public Properties ----------------------------------------------------
4d6c3c157705c101f044293dd642b62683918dedDav Glass Default options for CSS requests. Options specified here will override
4d6c3c157705c101f044293dd642b62683918dedDav Glass global defaults for CSS requests.
4d6c3c157705c101f044293dd642b62683918dedDav Glass See the `options` property for all available options.
fb1acfadd2c965ce38a6caa9cfa16e051ab70702Dav Glass @property cssOptions
fb1acfadd2c965ce38a6caa9cfa16e051ab70702Dav Glass @type Object
4d6c3c157705c101f044293dd642b62683918dedDav Glass @since 3.5.0
9ce5c4aa30657fb7e4ef73dca0ab98c7a42d4cd4Dav Glass Default options for JS requests. Options specified here will override global
9ce5c4aa30657fb7e4ef73dca0ab98c7a42d4cd4Dav Glass defaults for JS requests.
9ce5c4aa30657fb7e4ef73dca0ab98c7a42d4cd4Dav Glass See the `options` property for all available options.
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass @property jsOptions
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass @type Object
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass @since 3.5.0
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass Default options to use for all requests.
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass Note that while all available options are documented here for ease of
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass discovery, some options (like callback functions) only make sense at the
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass transaction level.
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass Callback functions specified via the options object or the `options`
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass parameter of the `css()`, `js()`, or `load()` methods will receive the
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass transaction object as a parameter. See `Y.Get.Transaction` for details on
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass the properties and methods available on transactions.
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass @since 3.5.0
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass @property {Object} options
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass @property {Boolean} [options.async=false] Whether or not to load scripts
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass asynchronously, meaning they're requested in parallel and execution
20128fa09a6536ce0e00f7b6dab83ab3bca6b698Dav Glass order is not guaranteed. Has no effect on CSS, since CSS is always
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass loaded asynchronously.
20128fa09a6536ce0e00f7b6dab83ab3bca6b698Dav Glass @property {Object} [options.attributes] HTML attribute name/value pairs that
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass should be added to inserted nodes. By default, the `charset` attribute
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass will be set to "utf-8" and nodes will be given an auto-generated `id`
9ce5c4aa30657fb7e4ef73dca0ab98c7a42d4cd4Dav Glass attribute, but you can override these with your own values if desired.
9ce5c4aa30657fb7e4ef73dca0ab98c7a42d4cd4Dav Glass @property {Boolean} [options.autopurge] Whether or not to automatically
9ce5c4aa30657fb7e4ef73dca0ab98c7a42d4cd4Dav Glass purge inserted nodes after the purge threshold is reached. This is
9ce5c4aa30657fb7e4ef73dca0ab98c7a42d4cd4Dav Glass `true` by default for JavaScript, but `false` for CSS since purging a
20128fa09a6536ce0e00f7b6dab83ab3bca6b698Dav Glass CSS node will also remove any styling applied by the referenced file.
9ce5c4aa30657fb7e4ef73dca0ab98c7a42d4cd4Dav Glass @property {Object} [options.context] `this` object to use when calling
9ce5c4aa30657fb7e4ef73dca0ab98c7a42d4cd4Dav Glass callback functions. Defaults to the transaction object.
09547accdabd440af5613767ba0eda138a7f1ffcDav Glass @property {Mixed} [options.data] Arbitrary data object to pass to "on*"
09547accdabd440af5613767ba0eda138a7f1ffcDav Glass @property {Document} [options.doc] Document into which nodes should be
09547accdabd440af5613767ba0eda138a7f1ffcDav Glass inserted. By default, the current document is used.
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass @property {HTMLElement|String} [options.insertBefore] HTML element or id
11173168fe9e382ff5a815fcf26d1686a0065c64Dav Glass string of an element before which all generated nodes should be
4d6c3c157705c101f044293dd642b62683918dedDav Glass inserted. If not specified, Get will automatically determine the best
4d6c3c157705c101f044293dd642b62683918dedDav Glass place to insert nodes for maximum compatibility.
fb1acfadd2c965ce38a6caa9cfa16e051ab70702Dav Glass @property {Function} [options.onEnd] Callback to execute after a transaction
fb1acfadd2c965ce38a6caa9cfa16e051ab70702Dav Glass is complete, regardless of whether it succeeded or failed.
fb1acfadd2c965ce38a6caa9cfa16e051ab70702Dav Glass @property {Function} [options.onFailure] Callback to execute after a
fb1acfadd2c965ce38a6caa9cfa16e051ab70702Dav Glass transaction fails, times out, or is aborted.
4d6c3c157705c101f044293dd642b62683918dedDav Glass @property {Function} [options.onSuccess] Callback to execute after a
4d6c3c157705c101f044293dd642b62683918dedDav Glass transaction completes successfully with no errors. Note that in browsers
4d6c3c157705c101f044293dd642b62683918dedDav Glass that don't support the `error` event on CSS `<link>` nodes, a failed CSS
4d6c3c157705c101f044293dd642b62683918dedDav Glass request may still be reported as a success because in these browsers
e185b559bf5512df7169f7901db9b2ec3771260bDav Glass it can be difficult or impossible to distinguish between success and
4d6c3c157705c101f044293dd642b62683918dedDav Glass failure for CSS resources.
4d6c3c157705c101f044293dd642b62683918dedDav Glass @property {Function} [options.onTimeout] Callback to execute after a
4d6c3c157705c101f044293dd642b62683918dedDav Glass transaction times out.
e185b559bf5512df7169f7901db9b2ec3771260bDav Glass @property {Number} [options.pollInterval=50] Polling interval (in
4d6c3c157705c101f044293dd642b62683918dedDav Glass milliseconds) for detecting CSS load completion in browsers that don't
4d6c3c157705c101f044293dd642b62683918dedDav Glass support the `load` event on `<link>` nodes. This isn't used for
4d6c3c157705c101f044293dd642b62683918dedDav Glass @property {Number} [options.purgethreshold=20] Number of nodes to insert
e185b559bf5512df7169f7901db9b2ec3771260bDav Glass before triggering an automatic purge when `autopurge` is `true`.
e185b559bf5512df7169f7901db9b2ec3771260bDav Glass @property {Number} [options.timeout] Number of milliseconds to wait before
4d6c3c157705c101f044293dd642b62683918dedDav Glass aborting a transaction. When a timeout occurs, the `onTimeout` callback
4d6c3c157705c101f044293dd642b62683918dedDav Glass is called, followed by `onFailure` and finally `onEnd`. By default,
4d6c3c157705c101f044293dd642b62683918dedDav Glass there is no timeout.
4d6c3c157705c101f044293dd642b62683918dedDav Glass @property {String} [options.type] Resource type ("css" or "js"). This option
4d6c3c157705c101f044293dd642b62683918dedDav Glass is set automatically by the `css()` and `js()` functions and will be
4d6c3c157705c101f044293dd642b62683918dedDav Glass ignored there, but may be useful when using the `load()` function. If
4d6c3c157705c101f044293dd642b62683918dedDav Glass not specified, the type will be inferred from the URL, defaulting to
56211303dc31245207d040e350e8a4a5e28f2f6bDav Glass "js" if the URL doesn't contain a recognizable file extension.
_pending: null,
_purgeNodes: [],
_queue: [],
Y.log('`Y.Get.abort()` is deprecated as of 3.5.0. Use the `abort()` method on the transaction instead.', 'warn', 'get');
transaction = null;
this._pending = null;
if (transaction) {
var urls = ['foo.css', 'http://example.com/bar.css', 'baz/quux.css'];
Y.log('foo.js failed to load!');
Y.log('foo.js was loaded successfully');
var urls = ['foo.js', 'http://example.com/bar.js', 'baz/quux.js'];
Y.Get.js(urls, function (err) {
Y.Get.js(urls, {
Y.Get.js([
{url: 'foo.js', attributes: {id: 'foo'}},
{url: 'bar.js', attributes: {id: 'bar', charset: 'iso-8859-1'}}
Y.Get.load(['foo.css', 'bar.js', 'baz.css'], function (err) {
_getEnv: function () {
return this._env = {
// https://developer.mozilla.org/En/HTML/Element/Script#Attributes
var requests = [],
Y.log('The `charset` option is deprecated as of 3.5.0. Set `attributes.charset` instead.', 'warn', 'get');
var transaction;
if (!this._env) {
this._getEnv();
this._next();
return transaction;
_next: function () {
var item;
if (this._pending) {
if (item) {
if (isTransaction) {
var self = this;
This object comes from the options passed to `Get.css()`, `Get.js()`, or
this._pending = null;
this._pendingCSS = null;
this._queue = [];
this._finish();
var self = this,
purge: function () {
attr;
return node;
_finish: function () {
if (errors) {
if (req) {
return Y.merge(this, {
if (el) {
self = this,
if (!node) {
if (isScript) {
function onError(e) {
function onLoad() {
if (isScript) {
Y.log("This browser doesn't preserve script execution order, so scripts will be loaded synchronously (which is slower).", 'info', 'get');
onLoad();
_next: function () {
if (this._pending) {
} else if (!this._waiting) {
this._finish();
var self = this,
if (newReq) {
if (isWebKit) {
} catch (ex) {
if (err) {
this._pending = null;
this._next();