Skip to content

Inline rendering with document.currentScript

Save

In brief

  1. Uses `document.currentScript` to replace an inline script with its evaluated result at runtime.
  2. Enables a tiny template language with a shortcut function like `$`.
  3. Reduces client-side template complexity without external dependencies.

Simon Willison highlights a JavaScript trick using `document.currentScript` to dynamically replace an inline script with its result when the page loads. This enables building a lightweight template language.

This summary gives you the essentials. The full article, its figures and quotes are on Simon Willison's Weblog.

Read the original article

AI-generated summary of the source, checked by rules. Report an error

Cookies and privacy

BrefAI only uses strictly necessary storage (language, theme, this choice). With your consent, we also measure traffic anonymously, without cookies, to improve the site. Learn more