This is really cool:
...blah... <script>writeImage("dog.jpg", "my dog")</script> ... blah blah...
Under the hood it works like this:
function writeImage(url, title) { document.write(` <img src="${url}"><div class="caption">${title}</div> `); }
And leads to:
...blah... <img src="dog.jpg"><div class="caption">My dog</div> ...blah blah...
Whoa, HTML templating? It inserts the stuff directly where the function is called, and it just works? And it's been available in browsers forever? Stop the presses, I gotta rewrite all my static sites
The same approach works for reusing chunks of HTML between pages:
<script src="common.js"></script> <script>writeMetaViewport()</script> ...page content...
when in common.js you have something like this:
... continue reading