3 ms·
I was only describing the initial idea. In production I use an intermediary step where all of my templates are actually re-processed back into raw javascript st
by Pewpewarrows 15y ago
I was only describing the initial idea. In production I use an intermediary step where all of my templates are actually re-processed back into raw javascript strings and served inside my minified/compressed/cached js file. I use a central access point that knows to grab the templates from a javascript object namespace instead of the innerHTML of an id when not in DEBUG mode. So while it still technically uses javascript strings at the end of the day, that's not how I develop them. For the average developer that's just looking to get easier maintenance over javascript templates, script tags with ids is the way to go.
"Simple" str1 + data + str2 might fly for a trivial one to two page website, but quickly devolves into an unmaintainable mess of spaghetti code as project sizes increase. I don't know of any modern programmer that would ever advocate for string concatenation over string interpolation via sprintf/templating/etc. I should also hope you're not trying to parse the strings yourself manually, regex'ing variables into it. There are tons of fast and efficient template libraries to choose from instead.