7 ms·
> Is this news at this point? If you started your career in the last 5-10 years then yes, it might be news. An entire generation of web developers has been tr
by arrowsmith 3y ago
> Is this news at this point?
If you started your career in the last 5-10 years then yes, it might be news.
An entire generation of web developers has been trained to think that every app big and small needs to be a convoluted SPA. The results are a disaster.
- eropple 3y ago"A convoluted SPA" is fully orthogonal to React. If you're making a blog into a SPA, that's a you problem. It's been possible (and recommended for many things!) to just bake a static website with React and use JSX as a templating language for a long time.
- arrowsmith 3y agoWhy would you need JSX for a static website? If you need JS then it's not "static".
- nesarkvechnep 3y agoBecause they only know JS and it’s ecosystem.
- ylyn 3y agoYou can render JSX at build-time. So it's just a templating language, as the parent comment said.
- eropple 3y agoReact is completely happy to spit out a DOM tree as HTML for you; wiring up the in-browser JavaScript side of React is optional. This is how static site generators like Gatsby or NextJS work (with some hacks that as a user you don't really care about) and (eliding some detail) how React Server Components now work generally. I've also used it to generate email templates[1] with some success, too. I use JSX because it's a nicer templating system than EJS or similar. It allows me to write components to encapsulate reused fragments rather than text manipulation. And I like it, which counts for something. Candidly, this is something that people who fulminate about React probably should know before they start talking. [1] - https://github.com/eropple/rx-mailer https://github.com/eropple/rx-mailer
- Capricorn2481 3y agoObviously there's a spectrum. A static website just means the files are served statically from a folder, and routing is just the folder path. You can still serve JS files and have a static website. If you put an alert on a button, you're not suddenly a SPA
- eropple 3y agoIt's more than that: you can just call methods in ReactDOMServer to get a DOM tree. The tools to wrap this vary widely; you can use Gatsby (ehh) or NextJS (yeah!) to do it if you want a full-featured framework around all of it, you can use something like react-snap if you want something simple and less all-in, or you can just call them yourself and plop some files in a build directory.
- post-it 3y agoGenerally, a static website refers to any website where the server just serves files rather than running application code for each request. JS runs on the client. For example, I've been working on a character generator for the Inquisitor tabletop game. It's completely static because I just SFTP the build output to my webserver, but it uses React and JSX.
- codethief 3y agoYou're missing OP's point. The website can be fully static (even without any JS) but you could still use JSX/React to generate it (during build time, not runtime). If you've ever had to build a static website from scratch, with the same navigation, footer etc. on each page, and without using frames, then you'll appreciate the amount of work that a templating engine saves you (whether JS-based or else).
- ehnto 3y agoI think you all missed GPs point, JS is barely required, let alone an SPA framework, let alone static generation in an SPA framework, etc.
- c-hendricks 3y agoAnd you're missing the other GPs point. Even when building a static website, you might want to reuse components. Or use shared components. Or do some logic. Or easily compose things. Note they said "JSX as a templating language". Why worsen the experience using Python + Jinja when you're just building a static site.
- baobabKoodaa 3y ago[flagged]
- ehnto 3y agoMm, herein lies the problem, I was not thinking about Python at all, and I suspect we are all thinking about various different tools. A static site is necessarily not dynamic though, as soon as you need dynamic features you need to reach for one tool or another. "Static site generators" are just dynamic sites with a pre-compile step instead of JIT. When I think of a static site, I am thinking HTML, CSS, some server side includes for header and footer. A bit of vanilla JS if you absolutely need it. Apache and nginx both have native template includes so you don't even need an extra language like py or php.
- 3y ago
- zwily 3y agoStatic doesn’t mean no JavaScript. Usually it means it’s not rendered on the server. Every time i start making a static website, i end up needing to include a table (or some other structured display of data) and then just switch to JSX to render the data with a loop. Sometimes i then render it as html and deploy, and sometimes i deploy it as react. But that’s how i usually end up using React even when static.
- satvikpendem 3y agoIndeed, static just means that the site files can be on a CDN and not need to change. Technically, SPAs are also static, if they spit out pure HTML, CSS and JS files that you can put on a CDN.
- bdcravens 3y agoYou use JSX the same way you'd use PHP - it just compiles into HTML. In this case, you just save the output after compiling it once. (as you can with the dozens or hundreds of non-JS options that do the same)
- bdcravens 3y agoIt's also been possible for 30 years to do the same with languages like PHP, ColdFusion, etc, no build steps necessary, and HTML is your "templating language".
- robertoandred 3y agoPHP pages absolutely have to be built/rendered.
- paulryanrogers 3y agoI think the distinction is that PHP is interpreted in real time most often. So there is rarely a separate build step.
- robertoandred 3y agoIt’s a build step that happens every time the page is loaded instead of once when it’s deployed.
- paulryanrogers 3y agoThen arguably JS is worse, since any 'build' steps preceding it don't bypass the (client side) interpreter either. Except perhaps if WASM is involved.
- eropple 3y agoThat's not true, though; JSX can be entirely prerendered server-side. If you don't write client-side JavaScript, you're not going to get client-side JavaScript (modulo maybe a thin hydration layer if you're using particularly old tools, but nothing running pervasively). Your code becomes HTML files. It's more Hugo/Jekyll than it is "a SPA". I am unaware of a major PHP framework that is designed around similar, though it may exist.
- 3y ago
- PrimeMcFly 3y agoYou think they would have discovered Flask or something similar just out of personal curiosity.
- jamil7 3y agoThey won’t touch anything that isn’t Javascript.
- bdcravens 3y agoI think a culture has been created where anything resembling server-side rendering (other than Node spitting out JSON) is legacy to be avoided ..... until of course the Javascript creates its own convoluted version of server-side rendering, which is revolutionary and the new hotness.
- joseda-hg 3y agoAren't those just the server-side components from React?
- PrimeMcFly 3y agoI'm not really in webdev, although I still do django sites for people sometimes, amazed and glad I had no idea that's how things had gone.
- satvikpendem 3y agoThe main benefit to JS being used as a server side rendered and client side rendered language is that you have a lot more control over which parts you want on the server vs the client, and you can introduce hydration where needed. You technically could do that in PHP and other non JS languages but that's annoying because you'll be mixing multiple languages together and it would be more clunky. So yes, there is some "revolutionary" benefit to having everything in JS/TypeScript.
- TX81Z 3y agoMy least favorite JavaScript argument is “Instead of using one good language for the backend and one lousy one for the front end, we’ll rewrite ALL the code in the lousy language to keep it easy!” I fail to understand why anybody would use JavaScript - a language so bad everybody uses a series of wrappers around it - for anything they didn’t absolutely have to (e.g. client code). The entire point of the MVC architecture is to allow you to pick the best tools for the job. EDIT: I’m not saying PHP is good, though it’s better than JS. And TypeScript is still JavaScript with extra steps.