4 ms·
PHP got ridiculed for years for doing all the things all the other popular frameworks are coming around to support now. Server side rendering is particularly hi
by nexuist 5y ago
PHP got ridiculed for years for doing all the things all the other popular frameworks are coming around to support now. Server side rendering is particularly hilarious because it's like: oh, you're compiling .jsx files to .html now? Cool....can't imagine anyone ever did that before...
- jchw 5y agoCGI script style languages like PHP are only superficially similar to SSR.
- nexuist 5y agoIs it though? I remember injecting <php> tags in the middle of JS scripts to fill out variable values. I'm sure someone somewhere was using PHP to inject conditionally dependent JavaScript onto their page. Is that much different from Next rendering a React component on the backend, injecting it into HTML, and then injecting its corresponding component state into the JS bundle?
- jchw 5y ago...Yes? For one thing, PHP code runs inside the process of rendering HTML, but JS SSR runs under the process of a React JS app, running in Node. That alone is an absolutely massive difference. Not just on a technical level; React JSX also doesn't have nearly as much hazards surrounding HTML sanitization, for example, because JSX is a DSL that protects inputs with proper sanitization by default, among other practical differences. Another difference is that SSR is more flexible than for runtime environment; it is very often used as a static compilation technique, where it is run as a compilation step for a static site, but either way, it is not married to any specific runtime model, whereas PHP pretty much is (for now.) A closer analogue to what React does would be comparing XHP[1] to JSX, but even that misses the isomorphic aspect of a SPA with SSR, which is almost the entire value proposition, because it allows you to only need to write your component code once while reusing the same render cycle at browser runtime. It should be pretty evident that PHP-style CGI scripting is not ideal given that even early on many PHP apps moved to using template systems like Smarty and never actually embedding HTML directly into PHP code. [1]: https://github.com/phplang/xhp https://github.com/phplang/xhp
- wnevets 5y agoIts always amusing watching people "discover" things that already existed.
- eyelidlessness 5y agoThe reason SSR/SSG of JSX (or Svelte, Vue, Marko, whatever) is appealing isn’t simply that you can run it on server/build. The appeal is that you can use the same code client-side. And of course each such framework/library has its own value propositions that are useful in both contexts. An additional of JSX in particular is that it’s render-target agnostic. Yeah you can render JS/DOM, and HTML… and CLI, and native UI APIs, and smart TVs, and WebGL, and… (I know there are similar solutions for some of these in the others, but JSX was specifically designed to accommodate this.)