From 124ecaf8247af673109085eee8fab8d5f2bc7caa Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 6 Sep 2017 14:19:26 -0700 Subject: sandbox template cache --- ext/sb/js/sandbox.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'ext/sb') diff --git a/ext/sb/js/sandbox.js b/ext/sb/js/sandbox.js index bf1d56c1..0a0ff31b 100644 --- a/ext/sb/js/sandbox.js +++ b/ext/sb/js/sandbox.js @@ -23,7 +23,14 @@ window.addEventListener('message', event => { if (event.data.command === 'render') { - const template = Handlebars.compile(event.data.template || ''); + window.yomichan_cache = window.yomichan_cache || {}; + + let template = window.yomichan_cache[event.data.template]; + if (!template) { + template = Handlebars.compile(event.data.template || ''); + window.yomichan_cache[event.data.template] = template; + } + const result = template(event.data.data || {}); event.source.postMessage({result, sequence: event.data.sequence}, '*'); } -- cgit v1.2.3