Skip to content

an option to not use innerHTML and create elements using document.createElement #7908

@cyan-2048

Description

@cyan-2048

Describe the problem

for some reason on older browsers, rendering DOM Elements using text is actually slow(this is based on my experience with KaiOS 2.5 app development).

another problem with using innerHTML is that it preserves the whitespace and won't minify the html.

div1 = element("div");
div1.innerHTML = `<div class="cubesLoading svelte-768m3i"><span></span> 
					<span></span></div>`;
attr(div1, "class", "loading svelte-768m3i");

Describe the proposed solution

create elements

div1 = element("div");
div2 = element("div");
attr(div2, "class", "cubesLoading svelte-768m3i");
div1.appendChild(div2);
div2.appendChild(element("span"));
div2.appendChild(element("span"));
attr(div1, "class", "loading svelte-768m3i");

Alternatives considered

keep using innerHTML, but use a template and minify the html... This way a string can still be used, but without having to re-render it.

const template = element("template");
template.innerHTML = `<div class="cubesLoading svelte-768m3i"><span></span><span></span></div>`;

// function context
div1 = element("div");
div1.appendChild(template.cloneNode(true).content);
attr(div1, "class", "loading svelte-768m3i");

Importance

would make my life easier

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions