[web] Cache results from 'i18n' ajax controller (closes #4487856)
authorRémi Cardona <remi.cardona@logilab.fr>
Wed, 15 Oct 2014 18:23:54 +0200
changeset 10028 326fbc5c92b0
parent 10027 292c81246347
child 10029 832a2a0b7bd2
[web] Cache results from 'i18n' ajax controller (closes #4487856) This is a simple transient cache which will be forgotten as soon as the user leaves the current page.
web/data/cubicweb.ajax.js
--- a/web/data/cubicweb.ajax.js	Wed Oct 15 17:29:29 2014 +0200
+++ b/web/data/cubicweb.ajax.js	Wed Oct 15 18:23:54 2014 +0200
@@ -435,13 +435,21 @@
 }
 
 //============= higher level AJAX functions using remote calls ===============//
+
+var _i18ncache = {};
+
 /**
  * .. function:: _(message)
  *
  * emulation of gettext's _ shortcut
  */
 function _(message) {
-    return loadRemote(AJAX_BASE_URL, ajaxFuncArgs('i18n', null, [message]), 'GET', true)[0];
+    var form;
+    if (!(message in _i18ncache)) {
+        form = ajaxFuncArgs('i18n', null, [message]);
+        _i18ncache[message] = loadRemote(AJAX_BASE_URL, form, 'GET', true)[0];
+    }
+    return _i18ncache[message];
 }
 
 /**