by robocat · 4y ago · 0 comments
Personally, I think any reference to code within the HTML is bad - especially anything referencing code like the “clicked” identifier. It starts to look like line noise when there are many event handlers, and also I prefer my HTML to be as pure as possible (which makes validation and editing easy). Instead code and events within the component JavaScript/TypeScript should reference named nodes within the HTML template - nodes named by purpose.
I wrote a frontend framework doing this, and it worked really freaking well and components were a pleasure to code. The template didn’t need any tricky parsing, instead it was just boring HTML. Never mixing HTML and strings avoided most XSS opportunities. Most of the DOM is inherently secure.
This allows the frontend to be simpler, while the backend is ironically also less complex because the only special feature you need is support for sending partial HTML (fragments). This as opposed to needing to embed your entire frontend framework in your backend to allow your website to load in a reasonable time, run in browsers with JS disabled, be easier to crawl, etc.
That said, do you have a link to your frontend framework? I always enjoy seeing different approaches to the same or similar problems.