Live data from Hacker News

URL-Driven State in HTMX

lorenstew.art

171–180 of 188 posts

Re: URL-Driven State in HTMX

#171

Earlier quoted context omitted.

Some dangers with injection attacks if you don't santitize inputs correctly, but this is probably faster than most templating languages like razor.

There are a lot of ways to manage this problem. My preferred path is to wrap interpolated fields with HttpUtility.UrlEncode() when I know a user can touch it and there are plausible reasons for allowing 'illegal' characters at form submit time. In terms of performance, it is definitely faster. The amount of time it takes to render these partials is negligible. You'd have to switch up your tooling to measure things in…

The only thing that would be comparable might be something like RazorSlices.

Re: URL-Driven State in HTMX

#172

Earlier quoted context omitted.

The only real use case for an SPA is something that has to continue to work offline. There are legitimate cases like this, but most apps developed as SPAs aren't it. > No SSR framework figured out how to do this because they thought about pages rather than experiences. Laravel, Blazor and apps designed around HTMX are all like this. "SSR framework" has literally nothing to do with "pages rather than experiences". Pag…

> The only real use case The original idea behind an SPA was to enable API-only backends (with static file service). I still think that's a very worthy use case. Why not decouple the backend from the concerns of particular views? It makes for a more complex frontend, but it also allows multiple, highly differentiated frontend apps to be build on top of a single set of backend APIs. Esri's ArcGIS Online powers a lot o…

That's not a use case, that's an implementation. What is the end user actually getting with this architecture that can't be obtained by the server-side one? Offline functionality is the only differentiating feature.

Re: URL-Driven State in HTMX

#173

Earlier quoted context omitted.

The browser gives you a full-blown programming language with a rich API, but it seems a lot of people avoid that in favor of smushing together a static view on the server side with little more than string interpolation.

HTML templating isn't just string interpolation, Its a whole templating engine. It's not like JSX, which is fake templating. Server side frameworks have real templating. Plus, you have to convert data to HTML somewhere. If you're using react you do this typically on the front end. You traverse and read JSON and convert it to HTML... Just like you would in PHP. Just, on the front end.

> You traverse and read JSON and convert it to HTML

It gets converted to DOM nodes, and there is zero HTML source involved when using a component toolkit. Whereas in PHP, you can do things like this and it won't make a peep:

    $foo = '>>>>';
    ?>
Other template engines like twig or blade will at least escape it by default, but of course have a syntax for interpolating it raw, otherwise they wouldn't be very useful as template engines. That's the sort of templating I'm talking about. JSX is a tree builder syntax that doesn't even produce strings at all on the client side, and when rendered in SSR, produces HTML source that's correct by construction (syntactically anyway). You can call that "fake templating", I'd say it's not templating at all.

Obviously there are other server-side template engines out there that are also correct in this fashion (HAML comes to mind), but I'm not referring to those, and neither is most of the "server-side is all you ever need" crowd.

Re: URL-Driven State in HTMX

#174

Earlier quoted context omitted.

> The only real use case The original idea behind an SPA was to enable API-only backends (with static file service). I still think that's a very worthy use case. Why not decouple the backend from the concerns of particular views? It makes for a more complex frontend, but it also allows multiple, highly differentiated frontend apps to be build on top of a single set of backend APIs. Esri's ArcGIS Online powers a lot o…

That's not a use case, that's an implementation. What is the end user actually getting with this architecture that can't be obtained by the server-side one? Offline functionality is the only differentiating feature.

For ArcGIS? Have you ever used that?

A similar system would be Figma - how do you build a server side Figma?

Re: URL-Driven State in HTMX

#175

Earlier quoted context omitted.

HTML templating isn't just string interpolation, Its a whole templating engine. It's not like JSX, which is fake templating. Server side frameworks have real templating. Plus, you have to convert data to HTML somewhere. If you're using react you do this typically on the front end. You traverse and read JSON and convert it to HTML... Just like you would in PHP. Just, on the front end.

> You traverse and read JSON and convert it to HTML It gets converted to DOM nodes, and there is zero HTML source involved when using a component toolkit. Whereas in PHP, you can do things like this and it won't make a peep: $foo = ' >>>>'; ?> Other template engines like twig or blade will at least escape it by default, but of course have a syntax for interpolating it raw, otherwise they wouldn't be very useful as te…

I haven't seen a project that uses PHP for templating in many, many years. PHP backends use a templating engine, not PHP. They also feature components.

Its the same level of abstraction as JSX but you also get type checking.

Re: URL-Driven State in HTMX

#176

Earlier quoted context omitted.

> The only real use case The original idea behind an SPA was to enable API-only backends (with static file service). I still think that's a very worthy use case. Why not decouple the backend from the concerns of particular views? It makes for a more complex frontend, but it also allows multiple, highly differentiated frontend apps to be build on top of a single set of backend APIs. Esri's ArcGIS Online powers a lot o…

That's not a use case, that's an implementation. What is the end user actually getting with this architecture that can't be obtained by the server-side one? Offline functionality is the only differentiating feature.

A use case for an architecture pattern is a way it could be used to implement something. The concept of a "use case" doesn't just apply to end-users of a software product.

> What is the end user actually getting

More things implemented in the products with less development time.

Re: URL-Driven State in HTMX

#177

Earlier quoted context omitted.

That's not a use case, that's an implementation. What is the end user actually getting with this architecture that can't be obtained by the server-side one? Offline functionality is the only differentiating feature.

For ArcGIS? Have you ever used that? A similar system would be Figma - how do you build a server side Figma?

I'm not sure what you're trying to argue. SSR sites and apps still have scripting and client-side interactivity, the only difference is where the rendering is happening. That's what SSR stands for. SSR switches from APIs exchanging JSON with heavy client-side rendering, to REST endpoints returning hypertext which eliminates the majority of client-side rendering.

Re: URL-Driven State in HTMX

#178

Earlier quoted context omitted.

For ArcGIS? Have you ever used that? A similar system would be Figma - how do you build a server side Figma?

I'm not sure what you're trying to argue. SSR sites and apps still have scripting and client-side interactivity, the only difference is where the rendering is happening. That's what SSR stands for. SSR switches from APIs exchanging JSON with heavy client-side rendering, to REST endpoints returning hypertext which eliminates the majority of client-side rendering.

How would you implement Google Maps as a SSR app? -- same question for ArcGIS, Figma, an arcade game, or a Zoom clone. It's a serious question -- do you think that would be possible for any of those?

I contend that to build a coherent, usable web app of any of those types, there has to be a lot of client-side scripting. Hence, a SPA is the best architectural pattern.

Sure, you could use SSR for the layout of the page... but in that case, why not skip HTML rendering altogether by shipping raw HTML/CSS for the app's layout? Then you'd only need JS to power the contents of s where the app's functionality is located.

Re: URL-Driven State in HTMX

#179

Earlier quoted context omitted.

> You traverse and read JSON and convert it to HTML It gets converted to DOM nodes, and there is zero HTML source involved when using a component toolkit. Whereas in PHP, you can do things like this and it won't make a peep: $foo = ' >>>>'; ?> Other template engines like twig or blade will at least escape it by default, but of course have a syntax for interpolating it raw, otherwise they wouldn't be very useful as te…

I haven't seen a project that uses PHP for templating in many, many years. PHP backends use a templating engine, not PHP. They also feature components. Its the same level of abstraction as JSX but you also get type checking.

I would love to see more server template engines on the abstraction level of JSX/TSX or better, but I can assure you that neither Blade nor Twig are among them. And I actually like Twig (yes, I still occasionally do templating).

Re: URL-Driven State in HTMX

#180

I think people are now ready for php. I bet it will be reinvented on top of nodejs.

I'd love to see a modern PHP without all the warts but with the ease of use.

That’s called Python or Ruby.

I’ve been building web apps since the ’90s, and I never understood the appeal of PHP. It was always a terrible language, and there were usually better alternatives available.

Post reply on HN