mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add template caching
This commit is contained in:
@@ -501,10 +501,13 @@ function getUrlSync(url, cache = true) {
|
|||||||
}).responseText;
|
}).responseText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const templateCache = {};
|
||||||
|
|
||||||
export function renderTemplate(templateId, templateData = {}, sanitize = true, localize = true, fullPath = false) {
|
export function renderTemplate(templateId, templateData = {}, sanitize = true, localize = true, fullPath = false) {
|
||||||
try {
|
try {
|
||||||
const pathToTemplate = fullPath ? templateId : `/scripts/templates/${templateId}.html`;
|
const pathToTemplate = fullPath ? templateId : `/scripts/templates/${templateId}.html`;
|
||||||
const templateContent = getUrlSync(pathToTemplate);
|
const templateContent = (pathToTemplate in templateCache) ? templateCache[pathToTemplate] : getUrlSync(pathToTemplate);
|
||||||
|
templateCache[pathToTemplate] = templateContent;
|
||||||
const template = Handlebars.compile(templateContent);
|
const template = Handlebars.compile(templateContent);
|
||||||
let result = template(templateData);
|
let result = template(templateData);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user