summaryrefslogtreecommitdiff
path: root/addons/web/static
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@odoo.com>2019-01-28 09:39:56 +0000
committerChristophe Matthieu <chm@odoo.com>2019-02-14 15:11:19 +0000
commitb49745e52d7a7bc27afd416206dcd5fa242aa07a (patch)
treeae6a047da7e77b951db241e1342278ce543972e2 /addons/web/static
parent7daa85dd12ff522be510bc2f8db1d968cae7d891 (diff)
[IMP] web_editor: lazy load the wysiwyg
Issue: wysiwyg asset slow down the loading of the website, error inadvertently introduced: https://github.com/odoo/odoo/pull/29775 The assets are now loaded assynchroneously, when the editor is needed, its assets will be loaded. closes odoo/odoo#30700
Diffstat (limited to 'addons/web/static')
-rw-r--r--addons/web/static/src/js/core/widget.js37
-rw-r--r--addons/web/static/src/js/fields/abstract_field.js10
2 files changed, 33 insertions, 14 deletions
diff --git a/addons/web/static/src/js/core/widget.js b/addons/web/static/src/js/core/widget.js
index b25cd99587b..d3b9cc1033c 100644
--- a/addons/web/static/src/js/core/widget.js
+++ b/addons/web/static/src/js/core/widget.js
@@ -84,6 +84,32 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, {
* @type {null|string[]}
*/
xmlDependencies: null,
+ /**
+ * List of paths to css files that need to be loaded before the widget can
+ * be rendered. This will not induce loading anything that has already been
+ * loaded.
+ *
+ * @type {null|string[]}
+ */
+ cssLibs: null,
+ /**
+ * List of paths to js files that need to be loaded before the widget can
+ * be rendered. This will not induce loading anything that has already been
+ * loaded.
+ *
+ * @type {null|string[]}
+ */
+ jsLibs: null,
+ /**
+ * List of xmlID that need to be loaded before the widget can be rendered.
+ * The content css (link file or style tag) and js (file or inline) of the
+ * assets are loaded.
+ * This will not induce loading anything that has already been
+ * loaded.
+ *
+ * @type {null|string[]}
+ */
+ assetLibs: null,
/**
* Constructs the widget and sets its parent if a parent is given.
@@ -115,13 +141,16 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, {
* @returns {Deferred}
*/
willStart: function () {
+ var defs = [];
if (this.xmlDependencies) {
- var defs = _.map(this.xmlDependencies, function (xmlPath) {
+ defs.push.apply(defs, _.map(this.xmlDependencies, function (xmlPath) {
return ajax.loadXML(xmlPath, core.qweb);
- });
- return $.when.apply($, defs);
+ }));
}
- return $.when();
+ if (this.jsLibs || this.cssLibs || this.assetLibs) {
+ defs.push(ajax.loadLibs(this));
+ }
+ return $.when.apply($, defs);
},
/**
* Method called after rendering. Mostly used to bind actions, perform
diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js
index 37d2f22ef55..edc7c03ac02 100644
--- a/addons/web/static/src/js/fields/abstract_field.js
+++ b/addons/web/static/src/js/fields/abstract_field.js
@@ -35,8 +35,6 @@ var field_utils = require('web.field_utils');
var Widget = require('web.Widget');
var AbstractField = Widget.extend({
- cssLibs: [],
- jsLibs: [],
events: {
'keydown': '_onKeydown',
},
@@ -183,14 +181,6 @@ var AbstractField = Widget.extend({
}
},
/**
- * Loads the libraries listed in this.jsLibs and this.cssLibs
- *
- * @override
- */
- willStart: function () {
- return $.when(ajax.loadLibs(this), this._super.apply(this, arguments));
- },
- /**
* When a field widget is appended to the DOM, its start method is called,
* and will automatically call render. Most widgets should not override this.
*