4 ms·
Traditional server-rendered pages would prioritize serving content first. Then they would sprinkle in some javascript to provide dynamic features(like navigatin
by smadge 11y ago
Traditional server-rendered pages would prioritize serving content first. Then they would sprinkle in some javascript to provide dynamic features(like navigating to new pages without refreshing). This is exactly what "isomorphic javascript" is providing now, in a very roundabout manner.
- chrisfosterelli 11y ago> sprinkle some javascript to provide dynamic features I've never seen any added javascript to a page that went as far as generating and rendering other pages completely, that's always been a refresh. If it's not then that's literally the same thing as a SPA, and is actually isomorphic javascript. The "sprinkled javascript" that your talking about was basically used to do some simple DOM manipulation and a few XHR requests. It is not the same as a full single page app that is bootstrapped from server-side markup.
- deleted 11y ago[deleted]
- smadge 11y ago> I've never seen any added javascript to a page that went as far as generating and rendering other pages completely, that's always been a refresh. pjax[1] does what you are describing. There are other similar libraries as well. On user navigation, it makes a XHR request to the server, and updates in place any changed DOM elements. I like this, because it progressively enhances the user experience. An application should focus on serving content quickly to the user, then improving the experience where browsers leave a gap. Notice that pjax provides the same functionality as an isomorphic javascript without inflicting upon the world server side javascript ;) [1] https://github.com/MoOx/pjax https://github.com/MoOx/pjax
- chrisfosterelli 11y agoAh, I stand corrected! I've never seen pjax before. That said, this project was created in February 2015... It's not that the "Traditional server-rendered pages" approach had been doing this for decades and isomorophic javascript simply reinvented the wheel here... this is a new project. I shouldn't have claimed that you need full javascript to do this, that was clearly wrong, but my point is that isomorophic javascript is not the same as the common traditional server-rendered pages used before javascript single page applications came around.
- firasd 11y agoIdeally there should be a way to render JavaScript on the server side for views/templates, like React, without having to write your whole backend in JS. In fact I just googled and found something like this in the reactjs commmunity repo: https://github.com/reactjs/react-php-v8js https://github.com/reactjs/react-php-v8js
- lucaspiller 11y agoOne easy solution is to have a server side application that just serves the view layer. That bit can be JavaScript, then your API can be whatever language you want.
- mercer 11y agoHa, just the other day I set up a wordpress site with react as the (server-side) view layer using v8js. Makes development a lot more fun.
- firasd 11y agoInteresting. I definitely want to experiment with something like that. Most examples I've seen of a WP theme in React (e.g. https://github.com/Automattic/Picard https://github.com/Automattic/Picard) use the new WP API and a node.js app. So there are (at least) two potential approaches to this.
- mercer 11y agoYeah, I considered that, and in some cases might take that approach. But in my particular case the websites need to be server-side for SEO, so it's mostly just that I want to use React for reusability and because I prefer it over wordpress theming with php tags. Furthermore, I can now use React and still deploy the site on a typical LAMP-stack cheap hosting!
- smadge 11y agoI just remembered this gem from the react community! react-magic [1] intercepts navigation and form submission, makes a XHR request, parses the response into JSX, and uses react to update the modified dom elements. I just tested it out on one of my projects, and it had a few issues. I wish this were production ready, because it seems like a very easy way to enhance a traditional server side rendering application. [1] https://github.com/reactjs/react-magic https://github.com/reactjs/react-magic
- brightball 11y agoIsn't that basically what Rails Turbolinks do?