Rediscovering `document.write()`: HTML Templating for Static Sites
2025-08-16
This article explores a clever use of JavaScript's `document.write()` function as a simple HTML templating engine for building static websites. The author demonstrates how to safely use `document.write()` to reuse HTML snippets, avoiding page repaints, resulting in fast and efficient static sites. They share usage tips, caveats, and comparisons with other approaches. While `document.write()` is deprecated, the author argues for its advantages in specific scenarios and provides two safety rules to mitigate potential risks. Alternatives like `document.currentScript.replaceWith()` are also discussed.
Read more