From bf67aca9517c1c3b2a5c32fdc1bccd95c3208232 Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Wed, 30 Aug 2023 10:54:50 +0200 Subject: [PATCH] fix: lazy template initialization --- src/js/template.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/js/template.js b/src/js/template.js index f87db70..8a706d2 100644 --- a/src/js/template.js +++ b/src/js/template.js @@ -1,5 +1,8 @@ -const template = document.createElement("div"); -template.innerHTML = ( +/** + @type null|HTMLDivElement + */ +let template = null; +const templateHTML = ( //'
' + @@ -31,6 +34,10 @@ template.innerHTML = ( ); export default function(tpl){ + if (!template) { + template = document.createElement('div'); + template.innerHTML = templateHTML; + } return (tpl || template).cloneNode(true); }