4 ms·
This advice is a bit misguided: > get it down to static HTML and CSS and maybe a tiny bit of enhancing JS, and pare away every byte you can. HTML is a languag
by jkoudys 7y ago
This advice is a bit misguided:
> get it down to static HTML and CSS and maybe a tiny bit of enhancing JS, and pare away every byte you can.
HTML is a language used for building your DOM. CSS is a language used for styling. JavaScript is also a language that can do those things, and focusing on the language used isn't going to help.
If the goal is to save space and power you can do it much better with JS. A lot of server side rendering, html caches, and static content is focused on good SEO and low latency, not small download size and power consumption.
You can fit a much smaller download into a stripped-down Gatsby site if you have a nontrivial amount of content. It also makes things like serving only much smaller versions of any images way easier. You can go even smaller with vanilla JS if you want.
- dreamcompiler 7y agoSpecifying content, styling, and layout are what HTML and CSS were designed to do, and they do it quite well. Throwing the bigger hammer of Javascript at this problem means anybody who likes to browse without Javascript (which is quite a few of us in this era of abusive ads and malware) is not going to see your site properly. It also means you've opened the door for some future maintainer to introduce a multi-megabyte Javascript library 98% of which isn't actually needed, and which will very much consume a lot more power on the client's platform than HTML and CSS. Never use a Turing-complete language to solve a problem that's already well-solved with a non-Turing-complete language. Especially when that non-Turing-complete language is already present on the client's machine. Most especially when you're talking about static sites for essential public information.
- dwheeler 7y agoActually, JavaScript often is not good for that either. Static sites compress really well, and static HTML typically renders orders of magnitude faster than running JavaScript to create commands to eventually do the same thing. In addition, running JavaScript is typically far more power draining on a client than rendering HTML. Web browsers are extremely optimized to render HTML. There is also the advantage of working correctly when people do not have JavaScript enabled. On the other hand, if you need a site to work even with spotty internet access, JavaScript is probably your answer. But these are generalities, you can probably find a thousand exceptions. It is hard to give truly general advice because there are so many exceptions. That said, there are many good reasons to have static sites when you have to scale up big. They typically can handle very large scales, and caching them the super easy. Whether or not that actually meets the requirements of a site is a completely different story.
- theandrewbailey 7y agoHTML is the serialized representation of a DOM. It's the closest to the metal that you can get. It's far more efficient at what it does (thus, faster, thus consumes less power) than JS does. Byte for byte, JS is the most expensive part of the web stack, whereas HTML is the cheapest.