I'll take option C) "Both, where appropriate". I'm working on a little side project that uses front end Mustache templating for allowing admins to build out some structured components, I can then reuse those same Mustache templates to render the components serverside for non-admin users consuming the service.
Odd, the article conclusion seems to directly contradict the title.
I've used both approaches over the years and they both seemed to work pretty well. The only differentiator I really noticed was that the single-page-app style (client) seemed to be more elegant on mobile, while the server rendering was easier to split into tabs on desktop browser.
I'm really a tab fanatic so have disliked the last few years of javascript everything on the client, where middle click stops working. Are there any solutions for that, that I've missed?
Links that represent navigation within the web app should still have a `href` attribute - even if click events are being handled with AJAX and pushState. That way middle-click, etc. work as expected.
Of course, some links don't actually represent navigation, so for them this isn't really applicable (e.g. a button to collapse an accordion-style view).
> Notably, neither of these pages has any external resources. I wanted to control for that variable and understand the best you could do theoretically with either approach.
That's not the theoretical best in any way. The theoretical best is script tag pointing to a popular CDN, which has been loaded by this or another site before and is already in browser memory when you open this page. Then your page can be basic template+data with no code inlined.
I think you may have misunderstood. He is referring to the data, not the code. That data is usually user-specific and using a "script tag pointing to a popular CDN" is very unlikely to be workable.
He's referring to both actually. No external resources means that the page he's testing contains all of: html boilerplate, templates, data, script that puts it together. Comparing that to an equivalent page with everything rendered is kind of like comparison between a static "hello world" page to a cms rendering a "hello world" page.
In reality you're likely to have the templates already cached from previous requests and the templates rendering framework available from a CDN. What you end up transferring to the user is actually the data + tiny part of the script that gets rendering started.
I know this is a vanishingly unpopular opinion these days, but personally I think that if your content can only be rendered by a user-agent with full JavaScript support, your content isn't a fully formed citizen of the Web.
Your content can't be archived properly by the Internet Archive.
Your content can't be accessed by anything user-agent less sophisticated than a full-blown browser.
Your content can't be indexed by a search engine that doesn't have the resources to crawl using full headless browsers.
Your content won't work with tools that attempt to scrape and expand content (think URL expansion on Slack, Twitter, Facebook etc).
(There's a very high chance that your content sucks in widely used screen readers as well)
HTML for content, CSS for presentation, JavaScript for behavior enhancement. Not everything has to be built like Trello.
This whole debate comes down to knowing whether you're building a content-focused site or a behavior-focused application. If you're building something like the New York Times or Wikipedia, then you are building a content-focused site, and you definitely shouldn't require javascript to render that content, for all the reasons you list (and probably more). If you're building something like (to use your example) Trello or (to use the author's) Basecamp, then you are building a behavior-focused application, and you can choose your approach based on other trade-offs, some of which are discussed in the article.
It definitely gets interesting in the middle. Something like Discourse is a content-focused site with a lot of app-like behavior, so they've built it as an app, but made sure to enable server-side rendering. Tons of things fall into this gray zone. I tend to think that "Universal JavaScript" would be a really good default go-to, and I'm hoping the tooling for it will continue to improve to the point that it's a no-brainer.
JavaScript became the browser language because it was originally intended to do so much less than it did. If the intention had been, from the beginning, to do, in the browser, all we are now doing with JavaScript, a much different language would have been used. And now people learn JavaScript as a first language and use it extensively server-side...
It's an interesting full circle, in some ways, as JavaScript was originally envisaged as "LiveScript" to run server side systems and quickly finished/renamed in a rush to capitalize on a quick need for browser capabilities.
Haha not to be confused with the later LiveScript made in 2011. And the JavaScript Wikipedia page also mentions two different languages named C-- (and I heard a bad joke today "what was this programmed in? C--?" that apparently was ignorant of either).
LiveScript was always a client-side language – Brendan Eich was hired to do “Scheme in the browser“, and it was called Mocha. They renamed it to LiveScript during the Netscape Navigator 2 beta cycle and, shortly later, to JavaScript as Sun's Java campaign started to get traction. At the time, the argument was that most of your app would run Java on your burly servers and the lighter-weight JavaScript in the browser for things like form validation.
Netscape's server product did add server-side JS but that was released later and neither their webserver in general or server-side JS were anywhere near as influential as the browser. Think about how many years it took JavaScript to become usable for apps even now and try to imagine what it was like back in 1996.
It definitely is a super interesting progression. It's fairly pointless to theorize about counterfactuals, but I'm of the belief that if somebody had attempted to design a system with the intention, from the beginning, to do, in the browser, all we are now doing with JavaScript, that the result would have likely been an over-engineered failure, solving the wrong problems in the wrong ways. I think the utter failure of applets written in Java (a "proper" language) gives some credence to that hypothesis.
By "vanishgly unpopular", you mean "always upvoted to the top of hackernews"?
The internet archive seems to do fine with JavaScript. As does most search engines.
Also, I know a blind person who tells me the best browser to use is.. safari on Mac. Full blown JS, everything works great.
At this point, javascript is a full part of the web. Making good quality, disable and accessible pages is hard enough, without having to effectively do it twice (with and without JavaScript), for an increasingly small set of use cases.
> if your content can only be rendered by a user-agent with full JavaScript support, your content isn't a fully formed citizen of the Web.
I actually agree, in a sense, but without the pejorativeness that I infer from your comment. The web apps that are reasonable to build in Angular/React/etc. without server-side rendering support are not traditional hypertext documents that would be archived by IA, indexed by a search engine, or viewed from Lynx. These are things like GMail or complex interactive dashboards (e.g. CRMs). In that sense they're not "fully formed citizens of the Web," if you believe that only traditional hypertext documents satisfy that requirement.
There are types of web sites that are a hybrid of the two, like a NYT or Medium article that is mostly text but also contains some interactive data visualizations. Those interactive components can reasonable be built in React or similar, and I don't see that as a problem, since you inherently need JavaScript to use those anyway, plus search engines will have no trouble indexing the text on the page.
At the end of the day though, tooling ought to be good enough to allow server-side rendering for UAs without JavaScript support.
I make sure all of my personal web projects are usable and visually appealing in Lynx. While I doubt many people are using the text-only browser these days, this approach does go quite a ways in making your site accessible to all.
This is a valid argument for also providing a useable non-script version of your side, i.e. doing graceful degradation. I absolutely agree that this is still an important thing to do in 2016.
However, I don't see how this is an argument for building only pure-HTML pages. Why can't I use scripting with client-side templates, so I get an its advantages for clients that support it and use a server-rendered version (ideally using the same templates) for clients that don't?
If anything I would see this as an argument for client-side templates, at least if you still want to use scripts for certain parts of your site. Because the other alternative - generating snippets of html on the server, then monkey-patching them into the current page via script - seems like the worst of both worlds to me.
It's less development work to do progressive enhancement than it is to do graceful degradation[0], because you don't duplicate effort. And IMO, the outcome is usually better, as well.
This is a valid argument for also providing a useable non-script version of your side, i.e. doing graceful degradation. I absolutely agree that this is still an important thing to do in 2016.
However, I don't see how this is an argument for building only pure-HTML pages. Why can't I use scripting with client-side templates, so I get an its advantages for clients that support it and use a server-rendered version (ideally using the same templates) for clients that don't?
If anything I would see this as an argument for client-side templates, at least if you still want to use scripts for certain parts of your site. Because the other alternative - generating snippets of html on the server, then monkey-patching them into the current page via script - seems like the worst of both worlds to me.
I'm not exactly trying to attain the platonic ideal of a web page, here. My goal is to build something that people find valuable, quickly. I don't care if it requires js to render, because it's not worth the tradeoff to try to get it to show up for that one guy trying to render a web page on his TRS-80.
>Your content can't be archived properly by the Internet Archive.
IA doesn't factor into 99.999% of what I build.
>Your content can't be accessed by anything user-agent less sophisticated than a full-blown browser.
I build things for browsers.
>Your content can't be indexed by a search engine that doesn't have the resources to crawl using full headless browsers.
I can barely be arsed to submit sitemaps to Bing.
>Your content won't work with tools that attempt to scrape and expand content
When supporting those things becomes a priority, I'll do so.
----
RMS looks at a microwave and writes an essay about whether or not the software that drives it needs to be FOSS.
Great, so your advice is if I can use a device that is a few years old, I just have to buy the latest version of $BRANDED_PRODUCT. Developers can actively support or resist this wasteful practice. It seems pretty clear where you stand on this.
I have no idea what you're trying to say. I'm not offering advice, I'm saying I build applications to be useful, not to conform to a set of abstract ideals. If 1% of visitors can't use it, I need to weigh the value of serving those 1% vs the value of spending my time building features.
I'm not Google or Facebook. My team at work is me and two co-ops. I'm not going to triple our development time just so I can get some Internet back pats from purists.
So you're countering one extreme position with another? The truth is that not every web app is meant to be a "fully formed citizen of the web". Users want their LOB app to be slick and responsive, and the time you spend making it accessible to a text-based browser is time you're not spending on features your customers actually want.
I completely agree with these points when you're writing hypertext.
But much of the web has gone beyond hypertext. Many sites are now using the web as device-independent application environment, that executes without having to install a runtime (Java, Flash) or runs in a proprietary ecosystem (iOS, Android).
Also, some browsers like Dillo or w3m do not support Javascript at all. I used to to use Dillo a lot on my old desktop computer (which only had 1 GB of RAM), because it could have 30-40 tabs open and still remain below 100MB of RAM. These days, more and more often, all Dillo or w3m will show me is a blank page.
Since you mentioned it in your post. What benefit is there to Slack if the internet archive can load the chat page? Is there any value to Google to indexing the slack app? There's nothing of value there to anything other than logged in users so why would they build for anything with the access level similar to an unregistered user?
On the other end, their home page should be accessible and some I can't check right now, I can only guess that it is.
The relevant question is: Why do user agents without JavaScript support still exist?
I don't care what kind of agents they are - bots from some sucky search engine like yandex, outdated screen readers or lynx installed on some freaky geeky nerd's Pentium 3.
Everything must be ES5-compliant these days. Period.
If my website cannot be archived by the Internet Archive (like anyone gave them a permission to do so, anyway), it's entirely their fault, not mine. And if I want to present my info to some link scrapers or aggregators, I'd rather generate an RSS feed. Or it would be much better if some JSON-based feed standard already existed for this purpose.
JavaScript doesn't just serve behaviour enhancement any more. It is a full-blown platform for the modern Web citizens.
Actually these client-side / server-side debates always go really really wrong.
Especially these two article's make really really awful assumptions.
There are use cases for client-side frameworks. There are even website's or i would call it applications that running behind firewalls that make good usages of such tools.
Also he mentioned two server-side template engine's in the linked article. JSP and ASP especially these two are the worst thing you could do. Mixing Code within your Template is by far worse than using the AngularJS template engine wisely.
I would rather prefer everybody to use mustache (even) on the server.
Performance in a template engine is also the least thing you should consider.
Bottom line in all this quibbling seems to really just be that some people like JS and want to JS-all-the-things. I like JS to some extent, but continue to dislike and resist the rise of JS-all-the-things. And I build rich and complicated applications people use to do their jobs every day.
I prefer server-side templates and rendering hands-down. This makes it absolutely trivial to build HTML for anything just by hitting a URL that represents it. It also makes it trivial to add caching of those fully rendered HTML blobs if desired/needed.
I prefer to keep my JS focused on interactions and behavior, not turning JSON data into UI components. I build most apps with a skeletal JS layer that knows how to grab the right item at the right URL when triggered by a user action, and what part of the page to place the returned HTML into. I find it pretty fun and challenging to see how dumb I can keep JS.
I despise the idea of building dual validation in the client and on the server. Fuck that noise. With a forms library that is tied to my models (something that exists in most mature frameworks), the server near-instantly validates and sends back HTML with errors marked if the form is invalid. Again, JS just has to know to PUT/POST the form, and display the response in the right spot. And those forms still work when you hit them by URL instead of through a fancy JS-ified UI. Makes it damn trivial to build dumb versions of an app that aren't broken and unusable. And I like the idea of being able to replace a backend that only has to keep the contract of returning HTML from an endpoint. Don't even need to modify the client-side JS that responds to user actions if I don't want to. Maybe, at worst, I update some ids and classes if I decide to modify the markup.
I've never joined the bandwagon of server-side JS and Node. Ultimately, I simply can't bring myself to want to use JS as the primary language for my work. Not to mention that JS tooling, npm, and different versions of ES is an abysmal headache that creates way too much mental overhead just to get started. It's nice to be able to pick a language that just runs on its runtime without needing to know or setup whatever the flavor-of-the-month transpiler is that lets me use classes and shit.
JSON is cool as a means of exchanging data with an API. I like that. It's predictable, standardized, and a helluva lot better than SOAP ever was. But I find working with APIs programmatically and providing UIs to humans are wholly different interaction models, and can't help but feel that we keep making presenting UIs to humans increasingly more complex than necessary. APIs provide a predictable interface for exchanging structured data. UIs are meant for interacting with that data.
The guy who thinks client-side rendering is wrong is using ASP and JSP as his example web development systems. Those are outdated technologies. (ASP pre-dates ASP.NET by years). Since he is using outdated technologies as a reference point, I am not surprised he has an outdated perspective on client-side templating.
Client-side templating comes with its own problems and advantages. You might not need or want it. A lot of times though you do.
But the original guy who is against it is so far behind.. give it a year or two when people are taking desktop apps and compiling them to web assembly and running them in web browsers. Then the advantages will be obvious. But that is almost a reality today and that person probably doesn't even know that web assembly exists.
Sorry but people need to try harder not to fall behind.
One premise of this article bothers me right off the bat.
I don't understand why, as an application developer, we wouldn't want to offload some of the computational load to clients instead of our own servers. That is a resource that scales far better with the number of users.
If servers only handled data instead of page rendering and so on, we'd need fewer of them to handle larger loads and also be a lot more robust to getting posted on HN or Reddit, etc.
>I don't understand why, as an application developer, we wouldn't want to offload some of the computational load to clients instead of our own servers. That is a resource that scales far better with the number of users.
Because obviously your goal is not to lighten your web servers, but to make your webpage faster to load and hence more appealing.
If offloading to the client is at odds with the page being faster (and at least in the previous years that had been the case with mobile and JS-heavy pages), then you should don't.
And whether this offloading to the client scales better with the number of users is besides the point it -- as you need to please each particular user.
I don't understand why people think serving a blank or janky page to your users is OK. There's no reason not to serve a completely rendered page from the server side and only enhance the UI with client-side rendering and navigation when there is a user action or other event after page load.
The test case used text in a table, which is an extremely poor example. Modern designs use a lot of images and CSS, where presenting a complete document and stylesheets allows much faster time to render than client-side rendering followed by fetching all those assets and applying styles.
The pain for your users is multiplied by the slowness of mobile devices/networks and the complexity of your UI's layout to render.
44 comments
[ 3.4 ms ] story [ 88.0 ms ] threadI've used both approaches over the years and they both seemed to work pretty well. The only differentiator I really noticed was that the single-page-app style (client) seemed to be more elegant on mobile, while the server rendering was easier to split into tabs on desktop browser.
I'm really a tab fanatic so have disliked the last few years of javascript everything on the client, where middle click stops working. Are there any solutions for that, that I've missed?
Of course, some links don't actually represent navigation, so for them this isn't really applicable (e.g. a button to collapse an accordion-style view).
> Notably, neither of these pages has any external resources. I wanted to control for that variable and understand the best you could do theoretically with either approach.
That's not the theoretical best in any way. The theoretical best is script tag pointing to a popular CDN, which has been loaded by this or another site before and is already in browser memory when you open this page. Then your page can be basic template+data with no code inlined.
In reality you're likely to have the templates already cached from previous requests and the templates rendering framework available from a CDN. What you end up transferring to the user is actually the data + tiny part of the script that gets rendering started.
Your content can't be archived properly by the Internet Archive.
Your content can't be accessed by anything user-agent less sophisticated than a full-blown browser.
Your content can't be indexed by a search engine that doesn't have the resources to crawl using full headless browsers.
Your content won't work with tools that attempt to scrape and expand content (think URL expansion on Slack, Twitter, Facebook etc).
(There's a very high chance that your content sucks in widely used screen readers as well)
HTML for content, CSS for presentation, JavaScript for behavior enhancement. Not everything has to be built like Trello.
It definitely gets interesting in the middle. Something like Discourse is a content-focused site with a lot of app-like behavior, so they've built it as an app, but made sure to enable server-side rendering. Tons of things fall into this gray zone. I tend to think that "Universal JavaScript" would be a really good default go-to, and I'm hoping the tooling for it will continue to improve to the point that it's a no-brainer.
Such a bizarre progression to me.
Netscape's server product did add server-side JS but that was released later and neither their webserver in general or server-side JS were anywhere near as influential as the browser. Think about how many years it took JavaScript to become usable for apps even now and try to imagine what it was like back in 1996.
Sources:
https://brendaneich.com/2008/04/popularity/
https://www.computer.org/csdl/mags/co/2012/02/mco2012020007....
https://www.w3.org/community/webed/wiki/A_Short_History_of_J...
The internet archive seems to do fine with JavaScript. As does most search engines.
Also, I know a blind person who tells me the best browser to use is.. safari on Mac. Full blown JS, everything works great.
At this point, javascript is a full part of the web. Making good quality, disable and accessible pages is hard enough, without having to effectively do it twice (with and without JavaScript), for an increasingly small set of use cases.
I actually agree, in a sense, but without the pejorativeness that I infer from your comment. The web apps that are reasonable to build in Angular/React/etc. without server-side rendering support are not traditional hypertext documents that would be archived by IA, indexed by a search engine, or viewed from Lynx. These are things like GMail or complex interactive dashboards (e.g. CRMs). In that sense they're not "fully formed citizens of the Web," if you believe that only traditional hypertext documents satisfy that requirement.
There are types of web sites that are a hybrid of the two, like a NYT or Medium article that is mostly text but also contains some interactive data visualizations. Those interactive components can reasonable be built in React or similar, and I don't see that as a problem, since you inherently need JavaScript to use those anyway, plus search engines will have no trouble indexing the text on the page.
At the end of the day though, tooling ought to be good enough to allow server-side rendering for UAs without JavaScript support.
However, I don't see how this is an argument for building only pure-HTML pages. Why can't I use scripting with client-side templates, so I get an its advantages for clients that support it and use a server-rendered version (ideally using the same templates) for clients that don't?
If anything I would see this as an argument for client-side templates, at least if you still want to use scripts for certain parts of your site. Because the other alternative - generating snippets of html on the server, then monkey-patching them into the current page via script - seems like the worst of both worlds to me.
[0]: https://www.w3.org/wiki/Graceful_degradation_versus_progress...
However, I don't see how this is an argument for building only pure-HTML pages. Why can't I use scripting with client-side templates, so I get an its advantages for clients that support it and use a server-rendered version (ideally using the same templates) for clients that don't?
If anything I would see this as an argument for client-side templates, at least if you still want to use scripts for certain parts of your site. Because the other alternative - generating snippets of html on the server, then monkey-patching them into the current page via script - seems like the worst of both worlds to me.
>Your content can't be archived properly by the Internet Archive.
IA doesn't factor into 99.999% of what I build.
>Your content can't be accessed by anything user-agent less sophisticated than a full-blown browser.
I build things for browsers.
>Your content can't be indexed by a search engine that doesn't have the resources to crawl using full headless browsers.
I can barely be arsed to submit sitemaps to Bing.
>Your content won't work with tools that attempt to scrape and expand content
When supporting those things becomes a priority, I'll do so.
----
RMS looks at a microwave and writes an essay about whether or not the software that drives it needs to be FOSS.
I make my food hot.
I'm not Google or Facebook. My team at work is me and two co-ops. I'm not going to triple our development time just so I can get some Internet back pats from purists.
But much of the web has gone beyond hypertext. Many sites are now using the web as device-independent application environment, that executes without having to install a runtime (Java, Flash) or runs in a proprietary ecosystem (iOS, Android).
On the other end, their home page should be accessible and some I can't check right now, I can only guess that it is.
I don't care what kind of agents they are - bots from some sucky search engine like yandex, outdated screen readers or lynx installed on some freaky geeky nerd's Pentium 3.
Everything must be ES5-compliant these days. Period.
If my website cannot be archived by the Internet Archive (like anyone gave them a permission to do so, anyway), it's entirely their fault, not mine. And if I want to present my info to some link scrapers or aggregators, I'd rather generate an RSS feed. Or it would be much better if some JSON-based feed standard already existed for this purpose.
JavaScript doesn't just serve behaviour enhancement any more. It is a full-blown platform for the modern Web citizens.
Especially these two article's make really really awful assumptions. There are use cases for client-side frameworks. There are even website's or i would call it applications that running behind firewalls that make good usages of such tools.
Also he mentioned two server-side template engine's in the linked article. JSP and ASP especially these two are the worst thing you could do. Mixing Code within your Template is by far worse than using the AngularJS template engine wisely.
I would rather prefer everybody to use mustache (even) on the server. Performance in a template engine is also the least thing you should consider.
I prefer server-side templates and rendering hands-down. This makes it absolutely trivial to build HTML for anything just by hitting a URL that represents it. It also makes it trivial to add caching of those fully rendered HTML blobs if desired/needed.
I prefer to keep my JS focused on interactions and behavior, not turning JSON data into UI components. I build most apps with a skeletal JS layer that knows how to grab the right item at the right URL when triggered by a user action, and what part of the page to place the returned HTML into. I find it pretty fun and challenging to see how dumb I can keep JS.
I despise the idea of building dual validation in the client and on the server. Fuck that noise. With a forms library that is tied to my models (something that exists in most mature frameworks), the server near-instantly validates and sends back HTML with errors marked if the form is invalid. Again, JS just has to know to PUT/POST the form, and display the response in the right spot. And those forms still work when you hit them by URL instead of through a fancy JS-ified UI. Makes it damn trivial to build dumb versions of an app that aren't broken and unusable. And I like the idea of being able to replace a backend that only has to keep the contract of returning HTML from an endpoint. Don't even need to modify the client-side JS that responds to user actions if I don't want to. Maybe, at worst, I update some ids and classes if I decide to modify the markup.
I've never joined the bandwagon of server-side JS and Node. Ultimately, I simply can't bring myself to want to use JS as the primary language for my work. Not to mention that JS tooling, npm, and different versions of ES is an abysmal headache that creates way too much mental overhead just to get started. It's nice to be able to pick a language that just runs on its runtime without needing to know or setup whatever the flavor-of-the-month transpiler is that lets me use classes and shit.
JSON is cool as a means of exchanging data with an API. I like that. It's predictable, standardized, and a helluva lot better than SOAP ever was. But I find working with APIs programmatically and providing UIs to humans are wholly different interaction models, and can't help but feel that we keep making presenting UIs to humans increasingly more complex than necessary. APIs provide a predictable interface for exchanging structured data. UIs are meant for interacting with that data.
You are wrong.
Client-side templating comes with its own problems and advantages. You might not need or want it. A lot of times though you do.
But the original guy who is against it is so far behind.. give it a year or two when people are taking desktop apps and compiling them to web assembly and running them in web browsers. Then the advantages will be obvious. But that is almost a reality today and that person probably doesn't even know that web assembly exists.
Sorry but people need to try harder not to fall behind.
I don't understand why, as an application developer, we wouldn't want to offload some of the computational load to clients instead of our own servers. That is a resource that scales far better with the number of users.
If servers only handled data instead of page rendering and so on, we'd need fewer of them to handle larger loads and also be a lot more robust to getting posted on HN or Reddit, etc.
Because obviously your goal is not to lighten your web servers, but to make your webpage faster to load and hence more appealing.
If offloading to the client is at odds with the page being faster (and at least in the previous years that had been the case with mobile and JS-heavy pages), then you should don't.
And whether this offloading to the client scales better with the number of users is besides the point it -- as you need to please each particular user.
The test case used text in a table, which is an extremely poor example. Modern designs use a lot of images and CSS, where presenting a complete document and stylesheets allows much faster time to render than client-side rendering followed by fetching all those assets and applying styles.
The pain for your users is multiplied by the slowness of mobile devices/networks and the complexity of your UI's layout to render.