Classic advancement of things. It is full circle but not back to the begining, it's a level higher. It looks like you're doing the same but you now have all the benefits of server side rendering AND front-end frameworks.
Right, looks like it's just preprocessing the content with a static site generator to insert markup + CSS classes around the different syntactical pieces. /shrug
There's a increasingly larger amount of web developers who are only "trained in React/Angular/Vue" and are unable to understand how to use or the trade-offs of regular websites using just HTML+CSS with only a little or no JS (that goes for both templated or fully static sites), and a surprising number of them even thinking they are some kind of "legacy technology".
At the very least, this kind of article is informative for that crowd.
I'm fascinated by this. It seems that for any developer with less than five years of industry experience there's a reasonable chance that they've almost exclusively worked in an SPA, JavaScript-for-everything environment.
I have a hunch that there are a lot of web professionals out there these days who genuinely don't know how to build a web application without JavaScript - POST forms, cookies and the like.
You should make a video with a rebranded Django as “Reinhardt, the Multi Page Application” and see how it goes. Just do the original Rails “blog in ten minutes” demo to show it goes beyond todo lists.
Although at that point one could also make use of the excellent pygments library from Python, to truly have no JS, if that was the point. It is used from inside many other languages' tools as well.
Well I for one wish I’d known about this (specifically constexpr.js) sooner. I like to develop sites with TS, but generally prefer to ship as little of it to the client as possible. There are a few solutions for this but most have some kind of compromise or another. It’s good to see another contender out there!
This is not new, but it's nice to spread awareness since it seems everyone loads it in the front-end nowadays and I've noticed that it also avoids the page moving around too much.
In https://documentation.page/ I'm using `markdown-it` with `prismjs` to generate the code snippets (see example on e.g. https://react-test.dev/). It's in fact a default helper, so you don't even need hacks:
import MarkdownIt from "markdown-it";
import Prism from "prismjs";
function highlight(str, lang) {
if (!lang || !Prism.languages[lang]) return;
return Prism.highlight(str, Prism.languages[lang], lang);
}
const md = new MarkdownIt({ highlight }).use(...
In Go we have https://github.com/alecthomas/chroma, and I implemented the lexer that the Caddy docs use for syntax highlighting the Caddyfile (see https://caddyserver.com/docs/caddyfile/concepts for example). What's cool about this is Caddy is serving the site from markdown files rendered via Go templates, with Chroma for code blocks. So Caddy can highlight its own config.
There’s a code parsing intrinsic complexity cost. It can be paid in space / memory by pre-rendering on the server or it could be pushed at runtime as JS and potentially as CSS (which I understand is Turing complete) but one way or another the cost will be paid.
It's funny to see us remembering that things can be done on the server. The trend to render everything client-side has always been troubling to me. Such a waste of resources (but it's not your resources, so developers don't care). Sure, things that are truly dynamic or are different for every user is probably usefully done on the client. But a static page with code samples can easily be rendered on the server, with syntax highlighting, and then cached. You only need to do it once, rather than hundreds or thousands of times on every client device.
The trouble generally is that JS is used despite the content being static, or independent of client behavior/usage.
That is, JS can be used to do everything but it is not optimal, or even near optimal (or even remotely close to) for many use cases. In terms of runtime or simplicity. But because it is capable and available, it has encroached into every niche (of html/css) until like any invasive species, it consumes and shreds through all available resources, collapses the whole ecosystem, and all complex creatures give way to a fresh start with new fairly rudimentary biology (wasm) trying to evolve towards and find a new stability point — hopefully one that does not invite a similar destructive species, but we’ll see how it goes
The browser is just a generalised client implementation where the application is streamed and sandboxed. It's similar to a native app written on Kotlin/Swift or desktop application written in C#/wpf.
The same logic could be applied to those client application technologies, too.
> Such a waste of resources (but it's not your resources, so developers don't care).
I've always wondered if it wasn't intentional. Things running on the client means they don't have to run on the server, and you can save money this way.
For things like syntax highlighting which is fairly cheap and done "once" I doubt resource usage is a consideration. However I won't be surprised if this is at least a consideration for bigger companies when they decide to make a relatively cheep API or a server-rendered app.
So many HNers pointing out that it was possible since the dawn of the web... yet the point of this article is that you can just add highlighting JS and constexpr.js will automatically optimize it. JS-based highlighters have all sorts of plugins, so it makes sense to reuse the effort.
So basically the script renders the JS-needed website, execute the JS as a build step and spit out the highlighted site. Pretty cool!
43 comments
[ 4.2 ms ] story [ 104 ms ] threadAnd now we are bringing these client-side libraries back to the server.
At the very least, this kind of article is informative for that crowd.
I have a hunch that there are a lot of web professionals out there these days who genuinely don't know how to build a web application without JavaScript - POST forms, cookies and the like.
The churn rate on junior developers is probably the single biggest factor in software over the past two decades.
Then you'll end up having a project with highlighting logic in css and js. That's less than optimal
In https://documentation.page/ I'm using `markdown-it` with `prismjs` to generate the code snippets (see example on e.g. https://react-test.dev/). It's in fact a default helper, so you don't even need hacks:
If you take this approach to the extreme, you should render to png on the server for display, and provide plain text for accessibility only.
Give up, do some super hacky unmaintainable css mess, or suck it up and use js...
That is, JS can be used to do everything but it is not optimal, or even near optimal (or even remotely close to) for many use cases. In terms of runtime or simplicity. But because it is capable and available, it has encroached into every niche (of html/css) until like any invasive species, it consumes and shreds through all available resources, collapses the whole ecosystem, and all complex creatures give way to a fresh start with new fairly rudimentary biology (wasm) trying to evolve towards and find a new stability point — hopefully one that does not invite a similar destructive species, but we’ll see how it goes
Even a basic thing, could be impossible in css.
All your css logic goes to trash. Or you can keep css logic and make a mess of a software
If you have done it in js, you'd be able to reuse some code.
How do you plan to style it with javascript without CSS? Rendering directly to canvas?
The same logic could be applied to those client application technologies, too.
I've always wondered if it wasn't intentional. Things running on the client means they don't have to run on the server, and you can save money this way.
So basically the script renders the JS-needed website, execute the JS as a build step and spit out the highlighted site. Pretty cool!
BTW: the markup grows substantially. It's worth having a simplification step. Also the old-school <tt> element is shorter and cooler than <span>.
If you highlight on the server:
pros: no javascript, can cache
cons: might be a way to inject scripts into everyone's browser, since the client has to trust the html from the server
--
If you write it on the client:
pros: server can't distribute injected scripts, server stores less things
cons: more javascript, every client has to do work
--
All software choices are weighing the pros and cons. Do the thing that lets you work quickly and safely.