Document.write
10 days ago
- #JavaScript
- #HTML
- #Web Development
- The article discusses the use of `document.write()` for HTML templating in static sites.
- It explains how `document.write()` can be used to insert HTML directly where the function is called.
- Two rules are proposed for safe use of `document.write()`: only call it at the document toplevel or in functions named 'write', and never use it to output `<script>` or `<style>` tags.
- The article highlights the benefits of using `document.write()` for simple sites, such as speed and ease of development.
- It mentions the drawbacks, including the JavaScript requirement and the deprecation of `document.write()`.
- Alternative methods like `document.currentScript.replaceWith()` are suggested for safer in-place element insertion.
- The article concludes with insights on SEO compatibility and the limitations of the discussed techniques.