Inline rendering with document.currentScript
- ID
- 36738
- Status
- summarized
- Published
- 18 Oct 2026, 5:11 AM
- Fetched
- 18 Oct 2026, 10:40 AM
- Provider
- Simon Willison
- Category
- developer-ai
- Original URL
- https://simonwillison.net/2026/Oct/17/document-currentscript/
- Source URL
- https://simonwillison.net/atom/everything/
Summary
- Score
- 4.5
- Created
- 18 Oct 2026, 10:40 AM
- Tags
- Audience
- developersvibe_coders
What happened
Simon Willison link-blogs a trick from Lean Rada: an inline `<script>` can replace itself at page load using `document.currentScript.replaceWith(...)`, e.g. `The year is <script>document.currentScript.replaceWith(new Date().getFullYear())</script>`. Wrapping it in a one-liner helper `$=(...n)=>document.currentScript.replaceWith(...n)` turns any static HTML file into a mini template language: `The year is <script>$(new Date().getFullYear())</script>`. Posted 17 October 2026; the only content is the snippet itself, no benchmarks, caveats, or browser notes.
Why it matters
It is a zero-dependency way to keep values like the current year correct in a hand-written static HTML page without adding a build step, a framework, or a server-side include. If you maintain small static pages, you can paste the two-line `$` helper and stop hand-editing dates; if you already run a templating or bundling step, this adds nothing and is not worth switching for.
Discussion angle
Try it live in the Meet: paste the `$` helper into a static page and check where it holds up and where it silently does nothing — particularly scripts that don't run at parse position — since the post itself lists no caveats.