Live data from Hacker News

Syntax Highlighting in a Webpage Without JavaScript

fctorial.github.io

41–44 of 44 posts

Re: Syntax Highlighting in a Webpage Without JavaScript

#41
post #39
post #23

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 s…

> 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.

Re: Syntax Highlighting in a Webpage Without JavaScript

#42
There are pros and cons to highlighting on the client vs the server.

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.

Re: Syntax Highlighting in a Webpage Without JavaScript

#43
post #23

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 s…

Css will work until a certain point. What do you do when css can't handle? Give up, do some super hacky unmaintainable css mess, or suck it up and use js...

What do you mean, "can't handle?"

How do you plan to style it with javascript without CSS? Rendering directly to canvas?

Re: Syntax Highlighting in a Webpage Without JavaScript

#44
post #31

Earlier quoted context omitted.

Css will work until a certain point. What do you do when css can't handle? Give up, do some super hacky unmaintainable css mess, or suck it up and use js...

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 a…

For example you can do a drop down menu in css. Then you have some new requirements that css alone can't do it.

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.

Post reply on HN