Hacker News new | past | comments | ask | show | jobs | submit login
Enhance: a web standards-based HTML framework (enhance.dev)
132 points by bpierre on Sept 26, 2022 | hide | past | favorite | 43 comments



saw Brian launch this at Cascadia JS recently, a very interesting "HTML first" approach. feel like the zeitgeist has swung really really hard towards (lasting) web standards so this is the natural culmination of that trend and maybe is the metaframework that really makes web components go mainstream.

also was discussed on the latest syntaxfm https://syntax.fm/show/515/wtf-is-enhance-framework

(disclosure, am tiny angel investor in Begin, but Enhance is really kind of a different project)


Why bother with the dependency hell of JavaScript and Node.js if you’re not forced to go the SPA route? Heck, even Deno would have been a more compelling platform.

If all this is is composing plain ol’ HTML, which are just strings, any language will do. We have file based routing in Go in less than 10 lines of code connecting filesystem calls to Go’s template package. We have live reload with Air, too, and the builds times are under a second. Another nice thing with go is Filesystem embedding, so we build the HTML strings straight into the binary and deploy the binary as is.


Well, this isn’t just server side HTML includes, so your commentary seems like a rambling about your favorite language.

It’s a framework that lets you write JS functions that are used to render HTML on the server but also run on the client for progressive enhancement which is what your Go pitch does not do.


> client for progressive enhancement which is what your Go pitch does not do.

We have progressive enhancement in our Go app based on HTMX.

Also see Rails/Turbo and Pheonix/Elixir.

Also, before the era of JS devs who only know the hammer of React and React-inspired HTML rendering libraries, there was PJAX to do progressive enhancement. It's not that hard of a problem to motivate reinventing the wheel HTML rendering wheel with yet-another-JavaScript-framework. In that light, it's probably better to just stick to React which provides a superset of functionality and is battle-tested, but I digress. Most of the original complexity of PJAX was smoothing out browser inconsistencies. It's way easier to add progressive enhancement with standardized HTML5 libraries.

https://pjax.herokuapp.com/

Observe how this JS library's source repo doesn't have a package.json and the vendor directory is rather shallow. The first commit was before Node.js even existed.

As for HTMX, it's a JavaScript library. It's 10kB with zero dependencies, and you can just drop-it in with a script tag. I never criticized JS or a particular JS library. My original comment is about the dependency hell (and quality) of Node packages.

> framework that lets you write JS functions

Why is it important to have a framework and to write it is as JS function? That's an incidental detail if the goal is to compose HTML.

> rambling about your favorite language.

No, JavaScript is my favorite language. I just don't like NPM culture. We chose Go because it made sense for our use-case, as opposed to Node.js being an automatic default just because it's a frontend hammer.


NPM is just a package manager - I don't get why it's blamed for everything wrong with the world. You can find same issues / challenges / dependency "hell" with any other popular language and its packages or equivalent. Maven certainly comes to mind.


> composing plain ol’ HTML, which are just strings

That way lies XSS attacks, might be better to have a DOM of some kind in your language.


The template library in Go’s standard library handles XSS.

Being a JavaScript-based doesn't preclude you from XSS, either.


Not a month goes by without any random web framework receiving a security update regarding XSS and the like.

You're better protected using web frameworks than trying to reinvent things by yourself, surely, but also let's not believe in miracles.


React/nodejs is nice if you do SSR for everything too since you can use some hydration to improve the UX and write all your view code (server and browser) in a single place with the same language.

Nodejs is a performant runtime and React is not only for creating SPAs.

How do you plan to add JS to your Go web app?


> How do you plan to add JS to your Go web app?

This is what I mean by Node.js being a hammer and everything looks like a nail.

You don’t need Node.js to write JavaScript.


> You don’t need Node.js to write JavaScript

Yes, but you generally do need NodeJS to access NPM packages, which will provide a ton of JavaScript functionality for free.

To the user who posed this question, I'm sure what they meant could be more charitably read as:

"How do you plan to access the thriving JS / NPM web ecosystem from another language ecosystem entirely?"

You've certainly listed some upsides to Go, but then your response to someone requesting a more honest analysis of the downsides is "Node.js devs are idiots". Hm.


I didn't say Node.js devs are idiots. My argument is that Node.js devs only knows Node.js and sees everything as a nail. You are projecting that that equates to idiocacy, and I won't argue.

> "How do you plan to access the thriving JS / NPM web ecosystem from another language ecosystem entirely?"

For our project, a search engine with interactive filtering capabilities, we don't plan or need to. With SSR, most logic is already handled by the server. This is a CRUD app. The set of libraries available in NPM that we might be interested would be a handful to zero. If it's that critical, we can just add a script tag. If it's a useful abstraction, it should be available on CDN. If it's not, and it's not succumbing to dependency hell, we can just copy and paste from NPM or Github. The JavaScript aspect is to add interactivity, and that's available thru DOM APIs and VanillaJS. NPM is besides the point.

I exit here because you're going in a circle presuming that it's not feasible to build web applications without Node.js' "thriving" ecosystem. Amazon, Google, and so many other apps precede Node.js. I shipped JavaScript-enriched web applications at a few of those companies without having to use NPM as the package manager.

Here is one of the most powerful text editors for the web (I've load tested that it can handle 80million+ line buffers, whereas VSCode edges out at <5million natively): https://github.com/ajaxorg/ace. It's a pretty complex JavaScript application but you can develop without ever needing to "build". They use NPM to run tests and some devtools like Eslint, but we've still managed to minification/bundling in Go.

I'm building a JavaScript-based text editor, too. Taking inspiration from Ace.js, it uses Makefile to "build". You can just run a static file server such as Python SimpleHTTPServer to host all the files in the directory. I still have and componentized HTML/CSS that are lazy-loaded, separated JS files, thanks to <500 bytes VanillaJS runtime based on HTMX. I do reach for libraries. For that, I look to https://js1k.com/ for inspiration. The libraries there have zero-dependencies. Their source code all fit in screen and I can just copy the relevant bits. This is very similar to pulling in dependencies in Go in that it's humanly possible to do a supply chain security audit, unlike the nature of NPM packages. Currently the text editor with handwritten VanillaJS + copy-pasted libraries can handle 120+ million line buffers.

Serious apps and businesses can be built without NPM. Inferring from HackerNews' JavaScript source, and the fact that it's written in Lisp, I doubt HN uses NPM. This doesn't stop HackerNews from being useful and valuable.


As someone who uses the JS ecosystem day in and day out (without either particular love or hated for it), I just wanted to say: Thanks for a detailed and informative post! It's neat to hear about other web stacks and their various pros and cons.

Different projects and teams have different requirements, and it's interesting to hear about other approaches.


> I didn't say Node.js devs are idiots

No, you said: "You don’t need Node.js to write JavaScript."

Then, as evidence, you said your simple CRUD app doesn't need JS, linked me to some NodeJS projects, and told me that the web was working before NodeJS. Technically true points but not really supporting the idea that Go is the correct language to write web apps with JS in.

I don't blame you for exiting, it's not a cohesive conversation, but your quick dismissal of a question about NodeJS that you proceeded to undermine by showing me how most people use NodeJS to write their JS projects is... confusing


> Technically true points but not really supporting the idea that Go is the correct language to write web apps with JS in.

If the project is live and is serving its purpose, and if that doesn't convince you that $INSERT_LANGUAGE is the correct language (whatever that means) then I don't know what will.

Care to clarify that "correct language" thing?


Perhaps "canonical" would be a better word, and as your links suggested, the canonical way to work on JavaScript-language capabilities is to use a JavaScript interpreter you can run outside the browser.

Not sure Go has one of those wired.


> JavaScript interpreter you can run outside the browser.

You're moving the fencepost.

This thread is about how to render composable HTML components. Why do you need to run a JavaScript interpreter to do that? You just need an HTML interpreter. We do have JavaScript and that interpreter is the web browser.

By your logic that the interpreter should be in the same language as the stuff being interpretted, why are we using JavaScript to interpret HTML?

My original criticism was also about the dependency hell/culture around the Node ecosystem, moreso than Node’s capabilities as an interpreter.


> This thread is about how to render composable HTML components

I quite literally joined the fray in response to a question that asked: "how do you add JavaScript to your web bundle?" To me, it would be appropriate to say: "the class of JavaScript we can easily support in this app must be exclusively browser-testable, and we ignore DX-style features JS devs expect as our app just rebuilds and reloads quickly"

> why are we using JavaScript to interpret HTML?

Who is doing that? We're using JavaScript to have dynamic HTML updates client-side, but calling that "interpreting" is hilarious.

> My original criticism was also about the dependency hell/culture around the Node ecosystem, moreso than Node’s capabilities as an interpreter.

Which makes it even more strange that you basically took a fat shit on Node.js with no expansion [0]

[0]: > How do you plan to add JS to your Go web app?

This is what I mean by Node.js being a hammer and everything looks like a nail.

You don’t need Node.js to write JavaScript.


I didn't post any links and I seriously lost the thread of the conversation here. Why would you need to run a JS interpreter to be able to include JS in a website?... Confusing.


> I didn't post any links and I seriously lost the thread of the conversation here

Indeed, my mistake; I assumed such a response to a comment challenging "the idea that Go is the correct language to write web apps with JS in" with a response like "[i]f the project is live and is serving its purpose, and if that doesn't convince you that $INSERT_LANGUAGE is the correct language" could only come from the person upstream.

That user themselves acknowledged that there isn't meaningful JS in their Go web app, which means it's NOT "serving the purpose" that we were discussing in this subtree of the thread.

> Why would you need to run a JS interpreter to be able to include JS in a website?

You usually need a language interpreter to develop features in that language, no? Developing your bundle in the browser is not known to be a high-quality workflow from the perspective of DX.

Anyways, this is all silly, people building HTML reports from non-JS languages are arguing you don't need JS to make client interactivity, naive stuff.


Well, I still don't think you need JS interpreter to simply include JS in your project e.g. PHP Laravel, Elixir Phoenix et. al. serve JS assets just fine via integration with webpack, esbuild and the like.


Sure, but this is a far cry from a bespoke Go creation - these are production grade libraries with serious dev hours backing them that are generating JS for you.


> told me that the web was working before NodeJS

Pretty much any company that was online before 2009. Amazon, Craigslist, Ebay, Google, Facebook.


> Why bother with the dependency hell of JavaScript and Node.js if you’re not forced to go the SPA route?

You don't need to be building an SPA in order to want to have some client-side javascript. And you may want to use some third-party libraries for your client-side javascript. Npm is a decent distribution channel / dependency manager for that purpose.


Wild to see file based routing come back, it was cool in 2002, then it was lame in 2012 and now it's cool again.


Modern static generators have been using file-based routing the entire time. I recently built something with SvelteKit, and the output was HTML and CSS (no JS emitted because none was needed on the client side).


Just like pizza, there is one for every season.


Given the track record on stability (or rather lack thereof) in the ecosystem around Node.js, it feels like a strange base on which to build "a dependable foundation for ... future-proof web applications".


If we're just returning HTML, why the need for the boilerplate in that .mjs file?

Why not have your framework find standard .html files in a well-known location and wrap them in the boilerplate for me?

That way, I don't even need to think of them as something else - they are just HTML - and the magic is happening with me even seeing the wand


Having a different way of doing things for static HTML doesn’t seem simpler than just writing a JS function with no arguments.

I suppose it’s a matter of taste.


"Just writing a JS function".

You continue not getting it. That's an unnecessary overhead. Strictly speaking, you don't need it. If you can get away with not including it then you absolutely should skip it.

You guys can take some lessons from the so called static site generators. They have the right idea. Also Svelte which kind of does something very similar (although it does compile things to more vanilla JS which I like because less frameworks and inclusions).


Why couldn't basic templating or includes have been built in HTML natively? It's stupid that you have to use a static generator, client-side rendering, or dynamic content generation just to get a website with consistent headers/footers on all pages.

I dream of being able to author web content with just a text editor.


This is actually part of HTML, but the API is a bit clumsy: https://developer.mozilla.org/en-US/docs/Web/Web_Components/...


If we're allowing Javascript in the picture, isn't this something that's always been possible?


> Why couldn't basic templating or includes have been built into HTML natively?

Because HTML started life as an SGML application/vocabulary, and with SGML having entities (and link process declarations/stylesheets) for exactly these purposes, there was no need to invent HTML ad-hoc mechanisms. SGML templating based on SGML LINK works in a push (event-driven) style, with fully type-checked and HTML-aware semantics, quite different from your typical pull style embedding of whole programming languages that spit out unescaped strings ([1]).

Of course, browsers never came around to implement even basic SGML features such as entities (except for character entity references), and by 1994 or so, JavaScript was already introduced, making any HTML evolution inessential by introducing a Turing-complete language into the mix.

[1]: http://sgmljs.net/docs/templating.html


Frames work for that, but are obviously deprecated. Slightly more server dependent, but you could use SSIs [0] for that.

[0]: https://en.wikipedia.org/wiki/Server_Side_Includes


The problem is that frames live in a separate DOM, so content inside them doesn't flow/resize with the page.


A good way to have file-system based routing is to actually use files. And the inclusion of common parts can easily be done on the server-side or locally on the development machine using PHP's include directive.

Using PHP as a template language, it is trivial to generate static HTML content by calling PHP from the command line on your files (this is easily automated to scale for many many pages website) to be able to host the result everywhere even on hostings that do not have PHP :).


This has some traits of astro.build, but the single file component is just a javascript function returning a bag of html. This is kind of nice since you don't need to know any new concepts.

Maybe it could be useful for the project to position itself against these other frameworks more directly?


so, this is php+apache's incarnation in js, yes?


So this is all SSR right? Where does persistence/database fit into this concept?


I look forward to new frameworks being easier to use and helpful. These new Frontend frameworks, React, Vue, Svelte, just made things 100 times more complicated. Sure they're useful for SPA's and certain use cases, but the majority of the web doesn't need to be over-engineered to the nth degree. I laughed hysterically when I learned Google wouldn't spider content properly on SPAs. Then laughed again when they had to build another app, such as Next, or Nuxt, just to do so.


It helps to be a bit more nuanced. I hate JS' guts, mind, you but even I know that Svelte makes things easier and more predictable.

That almost everything on the frontend is over-engineered, I don't think any reasonable programmer would disagree with. It's true.

But since people are stuck with HTML, CSS and JS they try hard to make it more manageable. Pieces of tech like HTMX and Svelte improve the status quo. Not everything is bad in there.

...That still doesn't mean I want to do frontend work though, heh.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: