Developers · Updated 18 Oct, 02:41 am IST
Tiny inline rendering trick using document.currentScript
Why it matters for readers: It shows a neat JavaScript trick that makes small inline templates possible with minimal code.
- The trick uses document.currentScript.replaceWith(...) to have an inline <script> replace itself with content at load time.1
- Example: <script>document.currentScript.replaceWith(new Date().getFullYear())</script> renders the current year in place.1
- Defining $=(...n)=>document.currentScript.replaceWith(...n) provides a concise shortcut so <script>$(...)</script> acts as a tiny template.1
Get a brief like this every morning
Uzha reads hundreds of sources and gives you the stories that matter for your work, with every source linked. Free.
Get started