Live data from Hacker News

Are Serverside Web Frameworks Becoming Irrelevant?

blog.recursivity.com

11–20 of 49 posts

Re: Are Serverside Web Frameworks Becoming Irrelevant?

#12
It might be very tempting to just use a REST API and a JS client for your web application. With the _escaped_fragment_ technique, you can even get indexed by Google (I'm not sure whether the other search engines already do this, but Google still is good for 90% of my search referrals, so it's ok for me).

The architecture is very clean. And you get a full third-party API "for free" instead of having to bolt it on afterwards (and maybe missing some stuff that can only be done in the web client).

Not only that, by the statelessness of REST you get really good scalability: Each request is independent of each other request, so you should be able to just add frontend- and backend-servers as you see fit without having to worry about global state.

Still, after having done just that (build a web application that is nothing but a JS frontend to a REST API - quite like the new twitter) with http://tempalias.com (source is available), I can tell you that it's not all rainbows and unicorns to misuse that saying once more.

One thing is Sammy, the client-side framework I used. It's quite easy to get lost in one big heap of application that's very hard to maintain. That is totally my mistake though and with a bit of additional experience and some help of require.js or something, I could fix that.

The other thing is UI. People are still used to the browsers page-loading-paradigm. In that case, the browsers themselves provide status update during requests. With AJAX, you'll have to do your own loading indicators and every site does it differently and no site as fine-grained as browsers (Connected, Waiting for reply, Loading... etc).

While the granularity of notifications can be fixed (best is to leave it as a single notification, but respond really quickly), you still don't solve the problem that it looks different on every site. This is a general problem of pure-AJAX sites.

Newtwitter suffers from this. Lately it's quite slow for me and I'm constantly wondering whether some JS has crashed or whether it is just slow.

And finally, sometimes, you have to do really convoluted solutions for problems which could ever-so-easily be solved by just being able to send a few dynamically generated bytes.

Of course, you could cave in and chose the impure solution, but I didn't want to which caused me some headache in my case, like not having access to the hostname of the 'd bookmarklet runner script (https://github.com/pilif/tempalias/blob/master/public/bookma...) which I now have to pass in on bookmarklet invocation.

To be honest though, over time, we'll learn to cope with such issues (and browsers might get a bit better in notifying users about AJAX connections going on) and at that point the advantages could really get into play.

After tempalias which was a personal fun-project, we decided to reuse this rest-only architecture for a project my company is currently working on, fully prepared to deal with the issues outlined here because, really, we believe that the benefits might well outweigh the issues.

Re: Are Serverside Web Frameworks Becoming Irrelevant?

#13
post #2

I've tried to accomplish a REST API + JS client on a few of my projects, but where I get hung up is session handling. What I've ended up doing is writing the REST backend and writing the presentation layer in something light, like flask or sinatra, just for session handling.

you shouldn't need to do session handling if you are going REST. Rest is all about not having state. If you need authentication, authenticate on every request. If your request needs some additional info to give a response, pass that information in when sending the request.

It's really a different paradigm and sometimes it can get really painful to move away from the way of thinking that we are used to.

Re: Are Serverside Web Frameworks Becoming Irrelevant?

#14
post #13
post #2

I've tried to accomplish a REST API + JS client on a few of my projects, but where I get hung up is session handling. What I've ended up doing is writing the REST backend and writing the presentation layer in something light, like flask or sinatra, just for session handling.

you shouldn't need to do session handling if you are going REST. Rest is all about not having state. If you need authentication, authenticate on every request. If your request needs some additional info to give a response, pass that information in when sending the request. It's really a different paradigm and sometimes it can get really painful to move away from the way of thinking that we are used to.

I realize that you don't want to maintain state in a REST api. It's not that it's painful to do something I'm use too (ie: session handling), it's just its painful implementing.

My point was that I totally agree with the notion of a REST-based service, but it's easier from an implementation perspective to have have web-heads for views (static files, session handling, etc) that interact with the application (REST) server.

Re: Are Serverside Web Frameworks Becoming Irrelevant?

#15
post #2

I've tried to accomplish a REST API + JS client on a few of my projects, but where I get hung up is session handling. What I've ended up doing is writing the REST backend and writing the presentation layer in something light, like flask or sinatra, just for session handling.

How I've done it is something like this:

(1) Client sends auth info to backend server

(2) Server sets auth cookie on client

(3) Every request goes through a proxy written in Ruby/EventMachine which either just passes through the request to the backend server if requesting something public or first checks that the client's auth cookie is valid if its requesting protected resources.

This certainly isn't as simple as it would be in a server-side framework, but otherwise it works pretty well.

Re: Are Serverside Web Frameworks Becoming Irrelevant?

#16
post #6

One good thing about JS and a REST backend: there will finally be widespread separation of UI and domain!

This whole separation of UI and domain is the kind of Ivory Tower academic nonsense perpetuated by the DDD folks and many, many others. Nowhere is this virulent plague more endemic than in the Java world. As the joke goes, the Java programmer's response to any problem is to add just one more layer of abstraction. And I say this as a Java programmer of some 10+ years experience so please don't take it as mindless Java…

Separating the domain from the UI is just common sense and good business practice. Having the two melded is probably the most common way for companies to get stuck using an old application. Their business logic (the real value) is stuck in a glob of UI outdated code (which no one cares about anymore).

I say this as a Smalltalk programmer of 10+ years experience. Unfortunately, it's often been the worst Smalltalk apps that have had the longest life. In those cases, it's just too horrible to migrate to a different environment, and the rate of change in the current application makes the opportunity cost of freezing ongoing development too painful. The result is often one or two failed Java projects seeking to replace the Smalltalk app, which continues to creak along beyond all expectations. Often, the apps with the good architectures got replaced quickly.

I think a lot of that could be fixed with automated translation to Groovy and some custom UI frameworks.

Re: Are Serverside Web Frameworks Becoming Irrelevant?

#17
post #7
post #5

No, they are not becoming irrelevant. Frameworks add significant value on the front end as well -- the easiest example is templating, which is a) not natively supported in HTML b) hard to fake with CSS/Javascript and c) virtually required for productivity, consistency, and maintainability. I suppose one could theoretically fake this by using a script to spit out static HTML served by Apache, but then the combination…

There are tools for templating with Javascript, for example https://github.com/jquery/jquery-tmpl I can imagine that's not so good for search engines.

I still, for the life of me, cannot understand why this is used. Why would you leave the users environment responsible for templating?

Re: Are Serverside Web Frameworks Becoming Irrelevant?

#18
It's probably just a question of server-side frameworks being more mature at this point in time, and client-side logic being a more fertile ground for innovation due to longstanding cross-platform roadblocks. A client-server architecture is always a balancing act, and it's just teetering a bit towards the client side at the moment.

The future is being able to divide work arbitrarily between front-end and back-end depending on the particular needs of your application.

Re: Are Serverside Web Frameworks Becoming Irrelevant?

#19
post #17
post #7

Earlier quoted context omitted.

There are tools for templating with Javascript, for example https://github.com/jquery/jquery-tmpl I can imagine that's not so good for search engines.

I still, for the life of me, cannot understand why this is used. Why would you leave the users environment responsible for templating?

I don't really get it either, but one reason I can think of is that it saves some bandwidth because sending the data that gets inserted into the template will probably be smaller than the HTML after templating.

Re: Are Serverside Web Frameworks Becoming Irrelevant?

#20
post #10
post #8

uh, if you stop working with server side frameworks, how do you serve information to the front end javascript framework? do you intend to just expose your database to the end user's browser?

You've then just moved all data processing to the front-end, and the MVC framework moves into the client. You are then charging the consumer a tax for the processing and battery power of a presentation that could have been served with an infrastructure designed to handle it. Moving UI to the client does nothing but move the UI to the client - it still has to be done and Javascript performance varies too much for this…

It's about moving the generation of HTML to the client. The concept of rendering the UI (using HTML) on the server was a step backward right from the beginning of the WWW. Servers are simply not needed to construct HTML.

I predict within a few years everyone will agree that all server-side HTML template languages (PHP, eRuby, JSP, Django etc) are obsolete. There will be a great normalization of server-side frameworks -- Ruby, PHP, Java, will essentially only be for shuffling data from your database to your client. The way it should have been all along.

Post reply on HN