{
  "id": 15538819,
  "title": "Inline rendering with document.currentScript",
  "url": "https://urgent.news/2026/10/19/inline-rendering-with-document-currentscript",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-19T01:02:55.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://leanrada.com/notes/inline-rendering-currentscript/"
  },
  "original_language": "en",
  "account": "For simple dynamic content rendering, you might not need advanced templating languages or PHP backends. The example phrase, \"Come on, it’s currentYear\", should render as \"Come on, it’s\" today. Instead of using IDs, classes, or querySelectors in your JavaScript, you can refer to the running script element directly using the document.currentScript property. The dynamic phrase \"Come on, it’s\" can then be written within the script as follows.\n\nThe code might seem wordy, but it can be aliased to a constant like $ via $=(...n)= document.currentScript.replaceWith(...n). This allows for a more readable and template-literal-like approach, even without explicit context.\n\nThis is the RenderJS custom element, which simply replaces itself with the result of its contents treated as JavaScript code. To use it, you must first name the tag, using an emoji (💲) as a workaround for the dollar sign ($) not being allowed in tag names. The name becomes j-💲, representing JavaScript.\n\nWhen employing this technique, it's recommended to include a noscript fallback for those who don't run JavaScript. This method may seem useful only for rendering the current year, but it can be applied to various scenarios, such as displaying relative dates, generating markup per character, or creating text animations.\n\nUnlike templating languages, you cannot perform data-driven templating using inline scripts. This is because data must be pre-injected into the global scope, and fetching data through inline scripts incurs an extra HTTP request, leading to potential performance issues. However, for personal projects, direct patching of data-driven HTML can be an effective alternative to traditional templating systems.",
  "summary": null,
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}