summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/core/session.js
diff options
context:
space:
mode:
authorVincent Schippefilt <vsc@odoo.com>2019-04-19 10:10:54 +0000
committerVincent Schippefilt <vsc@odoo.com>2019-05-20 08:52:18 +0000
commit8a28cc22fd242f5fb59f23d1443ed8ed438249d7 (patch)
tree85b2df5a1f58f84ee5ef931aaa31d175e5646f0c /addons/web/static/src/js/core/session.js
parentd9b0b09bd2a9a359ff04d28fd1a6f5c06f89f378 (diff)
[IMP] base,web: Improve webclient startup
Today, some resources that varies very infrequentely are requested on every page load: the menus, the translations and the qweb templates After this commit, there will be 2 improvements that will make the loading of the webclient faster: 1. cache almost static resources forever when loading the /web/ page, the user session will contain the cache key to be used to fetch these resources. As the content of the resource itself it used to compute the hash, the request can be put in cache by the browser forever (for a year). The up side is that in general less requests are needed to load the web client The down side is that the load time and number of queries of /web page has increased to include what is needed to compute the hash of translations, menus and qweb templates 2. trigger the loading of the menus before the download (and startup) of the JS and CSS assets: The menus contains the definition of the action, wich is the first thing needed to load a page in odoo. Starting the loading of the menu much earlier means that when they are not yet in the browser cache (see point 1), the browser does not need to wait for the entire assets to be downloaded and parsed before starting the 'load_menu' request, but instead start it immediately and hold onto a promise to be used instead of the rpc 'load_menu'. Because the request is done before anything else is loaded, including JQuery, it is made in vanilla JS. Co-authored-by: Julien Mougenot <jum@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/core/session.js')
-rw-r--r--addons/web/static/src/js/core/session.js15
1 files changed, 13 insertions, 2 deletions
diff --git a/addons/web/static/src/js/core/session.js b/addons/web/static/src/js/core/session.js
index 21103a9529a..e083bb71e7f 100644
--- a/addons/web/static/src/js/core/session.js
+++ b/addons/web/static/src/js/core/session.js
@@ -241,8 +241,11 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, {
});
},
load_qweb: function (mods) {
+ var self = this;
var lock = this.qweb_mutex.exec(function () {
- return $.get('/web/webclient/qweb?mods=' + mods).then(function (doc) {
+ var cacheId = self.cache_hashes && self.cache_hashes.qweb;
+ var route = '/web/webclient/qweb/' + (cacheId ? cacheId : Date.now()) + '?mods=' + mods;
+ return $.get(route).then(function (doc) {
if (!doc) { return; }
qweb.add_template(doc);
});
@@ -344,10 +347,18 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, {
getTZOffset: function (date) {
return -new Date(date).getTimezoneOffset();
},
-
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
+ /**
+ * Replaces the value of a key in cache_hashes (the hash of some resource computed on the back-end by a unique value
+ * @param {string} key the key in the cache_hashes to invalidate
+ */
+ invalidateCacheKey: function(key) {
+ if (this.cache_hashes && this.cache_hashes[key]) {
+ this.cache_hashes[key] = Date.now();
+ }
+ },
/**
* Reload the currencies (initially given in session_info). This is meant to