sandbox template cache

This commit is contained in:
Alex Yatskov 2017-09-06 14:19:26 -07:00
parent 9efe7bfe1b
commit 124ecaf824

View File

@ -23,7 +23,14 @@
window.addEventListener('message', event => { window.addEventListener('message', event => {
if (event.data.command === 'render') { 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 || {}); const result = template(event.data.data || {});
event.source.postMessage({result, sequence: event.data.sequence}, '*'); event.source.postMessage({result, sequence: event.data.sequence}, '*');
} }