diff options
| author | Christophe Matthieu <chm@odoo.com> | 2017-08-31 14:39:52 +0200 |
|---|---|---|
| committer | Christophe Matthieu <chm@odoo.com> | 2017-08-31 16:26:11 +0200 |
| commit | 95c2bd33a2e4bc5995b77c64c961e97db809e7f2 (patch) | |
| tree | 27c6d4104ae973ad293f0b8e5742f231f8362ff1 /addons/web/static/src/js/core | |
| parent | 6f60a9a1792f4390c883bc1dff5f595c84183e12 (diff) | |
[IMP] web: lazy load nvd3, ace and fullCalendar lib to reduce asset size
Diffstat (limited to 'addons/web/static/src/js/core')
| -rw-r--r-- | addons/web/static/src/js/core/ajax.js | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/addons/web/static/src/js/core/ajax.js b/addons/web/static/src/js/core/ajax.js index 63ee1f47c40..5bab96a0c1e 100644 --- a/addons/web/static/src/js/core/ajax.js +++ b/addons/web/static/src/js/core/ajax.js @@ -433,15 +433,52 @@ var loadXML = (function () { }; })(); -return { + +/** + * Loads the given js and css libraries. Note that the ajax loadJS and loadCSS methods + * don't do anything if the given file is already loaded. + * + * @param {Object} libs + * @Param {Array | Array<Array>} [libs.jsLibs=[]] The list of JS files that we want to + * load. The list may contain strings (the files to load), or lists of strings. The + * first level is loaded sequentially, and files listed in inner lists are loaded in + * parallel. + * @param {Array<string>} [libs.cssLibs=[]] A list of css files, to be loaded in + * parallel + * + * @returns {Deferred} + */ +function loadLibs (libs) { + var defs = []; + _.each(libs.jsLibs || [], function (urls) { + defs.push($.when.apply($, defs).then(function () { + if (typeof(urls) === 'string') { + return ajax.loadJS(urls); + } else { + return $.when.apply($, _.map(urls, function (url) { + return ajax.loadJS(url); + })); + } + })); + }); + _.each(libs.cssLibs || [], function (url) { + defs.push(ajax.loadCSS(url)); + }); + return $.when.apply($, defs); +} + +var ajax = { jsonRpc: jsonRpc, jsonpRpc: jsonpRpc, rpc: rpc, loadCSS: loadCSS, loadJS: loadJS, loadXML: loadXML, + loadLibs: loadLibs, get_file: get_file, post: post, }; +return ajax; + }); |
