Skip to content

perf(handler): consolidate per-component template scripts into single script tag#209

Merged
mohamedmansour merged 1 commit intomainfrom
perf/consolidate-template-scripts
Apr 9, 2026
Merged

perf(handler): consolidate per-component template scripts into single script tag#209
mohamedmansour merged 1 commit intomainfrom
perf/consolidate-template-scripts

Conversation

@mohamedmansour
Copy link
Copy Markdown
Contributor

Merge N individual <script> IIFE blocks into one consolidated <script> tag during SSR template emission. Templates using the standard IIFE pattern (w['tag']={...}) are extracted and combined into a single IIFE, reducing HTML parse overhead and eliminating N-1 script element evaluations.

Non-standard templates fall back to individual <script> tags for backward compatibility.

@mohamedmansour mohamedmansour force-pushed the perf/consolidate-template-scripts branch 4 times, most recently from 99f85cf to 5966851 Compare April 9, 2026 19:34
Strip the <script>...</script> wrapper from compiled template output in
webui-parser. Templates are now stored as raw JS IIFE strings in the
protocol.

- Parser: generates raw JS IIFE body, no <script> wrapper
- SSR (webui.rs plugin): wraps all templates in a single <script> tag
- Partials: sends raw JS strings directly in the templates array
- Router: evaluates raw JS via script element, no parsing needed
- FAST plugin: unchanged (uses <f-template> DOM elements)

This reduces SSR HTML size (1 script tag instead of N), eliminates
client-side <script> tag parsing for partial navigation, and cleanly
separates the transport format from the template content.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mohamedmansour mohamedmansour force-pushed the perf/consolidate-template-scripts branch from 5966851 to df5d9c9 Compare April 9, 2026 19:35
@mohamedmansour mohamedmansour merged commit d690975 into main Apr 9, 2026
21 checks passed
@mohamedmansour mohamedmansour deleted the perf/consolidate-template-scripts branch April 9, 2026 20:35
if (this.nonce) script.nonce = this.nonce;
script.textContent = tmpl;
document.head.appendChild(script);
document.head.removeChild(script);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Append then remove? I think a comment here would be good, I assume the IIFE inside the script executes, then is no longer needed so removed so as to keep the document as small as possible when switching routes, each of which may add and remove an IIFE. Is that correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants