From db593ec91429cff6c46a778ce9be240e7700ddcd Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Thu, 12 Jul 2012 11:27:46 +1200 Subject: [PATCH] MDL-33448 javascript: Added caching for the YUI instance used for debug in get_string --- lib/javascript-static.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/javascript-static.js b/lib/javascript-static.js index d1bc35a0faa..ed50150afb0 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -715,7 +715,13 @@ M.util.get_string = function(identifier, component, a) { // creating new instance if YUI is not optimal but it seems to be better way then // require the instance via the function API - note that it is used in rare cases // for debugging only anyway - var Y = new YUI({ debug : true }); + // To ensure we don't kill browser performance if hundreds of get_string requests + // are made we cache the instance we generate within the M.util namespace. + // We don't publicly define the variable so that it doesn't get abused. + if (typeof M.util.get_string_yui_instance === 'undefined') { + M.util.get_string_yui_instance = new YUI({ debug : true }); + } + var Y = M.util.get_string_yui_instance; } if (!M.str.hasOwnProperty(component) || !M.str[component].hasOwnProperty(identifier)) {