News for hackers. Stuff that matters.
Re:The Sun is Setting on Rails-style MVC Frameworks by tomdale on Friday February 24, 2012 @02:38PM (#3630638)
I wouldn't say that the sun is setting on Rails-style MVC frameworks, but I do think their role in the ecosystem is going to change. Before, most people could get away with writing the entirety of their app as a single Rails or Django app.

I think the shift first started with the ascendancy of native mobile apps. Now, developers had to seriously start considering their HTTP APIs as first-class citizens and not nice-to-haves. Once that happened, it's not a big leap to realize that treating your web application as somehow different from any of your native clients is a bit, well, insane. You can either choose to write a server that is a mix of JSON API and rendered HTML, with conditionals all about trying to figure out the right thing to render, or you can pull all of that logic out into a stand-alone JavaScript application, with better responsiveness to boot.

I think this approach is a winner. The server guys can focus on building a kick-ass server, and the front-end guys can build an awesome UI without having to muck about in the server bits.

One thing that still blows my mind is how hard it still is to get data from the server to the client. Everyone is writing custom code specific to their app. As the article says:

There's no reason for us to all separately think about these problems and solve them in a million different ways every time we're confronted with them. Aside from the years of wasted time this involves, we've also got a bunch of non-standard and sub-standard APIs to interact with, so all the client code needs to be custom as well and nothing is reusable.

I think this is a huge problem, and Yehuda and I are doing our part to try to solve it. Our Ember Data framework (http://github.com/emberjs/data), by default, assumes certain things, such as the names of your routes and how associations should be loaded. We want to enable people to start building apps right now instead of writing hundreds of lines of JavaScript that are custom to their application, and do it in a sufficiently comprehensive way that you very rarely need to drop down "to the metal." For example, we handle things like mutating associations on the client-side even before a guid has been assigned to a record.

Personally, I'm excited for how this is going to all shake out. I think Rails will continue to be an important piece in the toolchain, but it will no longer be the primary one, and I can't wait to see how it evolves to fill that role.

Re:The Sun is Setting on Rails-style MVC Frameworks by jshen on Friday February 24, 2012 @04:35PM (#3631166)
"You can either choose to write a server that is a mix of JSON API and rendered HTML, with conditionals all about trying to figure out the right thing to render, or you can pull all of that logic out into a stand-alone JavaScript application, with better responsiveness to boot."

You get better responsiveness if you send down pre-rendered html for the first page load. This means you still need the conditionals, or suffer on responsiveness.

Re:The Sun is Setting on Rails-style MVC Frameworks by jashkenas on Friday February 24, 2012 @06:45PM (#3631635)
Not in the slightest. Speaking categorically, JSON + templates are smaller to transfer over the wire than fully-rendered HTML -- and can be cached in exactly the same way ... even bootstrapped into a single HTTP request.

If you care about optimizing it, you can get your JS UI to render faster than the equivalent pre-rendered HTML would have.

Re:The Sun is Setting on Rails-style MVC Frameworks by jshen on Friday February 24, 2012 @07:47PM (#3631758)
I'm skeptical, but even so, I still need to render it on the server for googlebot.
Re:The Sun is Setting on Rails-style MVC Frameworks by ale55andro on Saturday February 25, 2012 @05:25AM (#3632655)
You can make your ajax content crawler friendly by following a specification google currently supports. I'm not particularly sure how much of this spec the other search engines support but it's a good start : https://developers.google.com/webmasters/ajax-crawling/
Re:The Sun is Setting on Rails-style MVC Frameworks by throwaway64 on Saturday February 25, 2012 @06:50AM (#3632748)
you still need to generate serverside HTML with this approach
Re:The Sun is Setting on Rails-style MVC Frameworks by ale55andro on Saturday February 25, 2012 @08:00AM (#3632842)
that's correct. You basically end up serving your content to crawlers dressed up in html. it's not very hard to do but it presents quite a challenge. We already do this for blogs where we serve alternate content for rss readers which is an apple and oranges comparison, however the idea is more or less the same. The takeaway is that there is a way to serve alternate content to search engines and it involves following an ajax crawling scheme.
Re:The Sun is Setting on Rails-style MVC Frameworks by stock_toaster on Friday February 24, 2012 @07:19PM (#3631696)
Don't you still have to render server side for crawlers and screen readers (accessibility)?
Re:The Sun is Setting on Rails-style MVC Frameworks by jashkenas on Friday February 24, 2012 @07:46PM (#3631754)
Many of these client-side JS-heavy apps are private "workspace"-like pages ... nothing that would ever need to be indexed by the Googlebot.

If you want to serve screen readers, then yes, you need to make sure you're serving only reader-compatible HTML and JavaScript.

Re:The Sun is Setting on Rails-style MVC Frameworks by stock_toaster on Friday February 24, 2012 @08:01PM (#3631782)
Yeah, that makes sense.
Re:The Sun is Setting on Rails-style MVC Frameworks by bill-nordwall on Friday February 24, 2012 @07:30PM (#3631723)
Nope. Screen readers have been able to handle javascript-generated content for years. According to WebAIM's most recent screen-reader survey, 98.4% of screen reader users have javascript enabled: http://webaim.org/projects/screenreadersurvey3/#javascript
Re:The Sun is Setting on Rails-style MVC Frameworks by mmahemoff on Friday February 24, 2012 @07:48PM (#3631764)
Crawlers, less so. The major search engines are getting smarter about it, but for now, you still need some kind of HTML output from the server if you really want to be indexed properly.

It doesn't rule out a pure client-side app at all, but you do have some extra work involved to output HTML from the server. Which is why NodeJS will ride on the coat-tails of this approach; less redundancy.

Re:The Sun is Setting on Rails-style MVC Frameworks by techwraith on Friday February 24, 2012 @08:00PM (#3631781)
Hah! "The major search engines" - you mean Google, right? ;)
Re:The Sun is Setting on Rails-style MVC Frameworks by eropple on Saturday February 25, 2012 @05:23AM (#3632652)
How effective is Javascript with screen readers, though? It's been a while since I played with a screen reader (late 2009 or so), but when I did even really simple things like a pop-up div confused it. It didn't inform the user that something new was being rendered or anything.
Re:The Sun is Setting on Rails-style MVC Frameworks by bill-nordwall on Monday February 27, 2012 @12:13AM (#3637864)
Surprisingly effective. A colleague of mine published some techniques to add consistency to Javascript events across screen readers: https://github.com/ryanfitzer/Accessibility
Re:The Sun is Setting on Rails-style MVC Frameworks by StavrosK on Friday February 24, 2012 @06:36PM (#3631610)
Is HTML rendering that much slower on the client than on the server?
Re:The Sun is Setting on Rails-style MVC Frameworks by jshen on Friday February 24, 2012 @07:45PM (#3631752)
I'm serving mostly cached html from the server.
Re:The Sun is Setting on Rails-style MVC Frameworks by hello_moto on Friday February 24, 2012 @03:56PM (#3630975)
The approach in the Java world for many years have been to implement Services (or Repository if it doesn't need a complex operations) and wrap them via facade pattern by utilizing:

- JAX-RS (RESTful)

- JAX-WS (WebService)

- MVC (view-based web-app)

And in contrast to what people believe, you don't need to write tons of code and still get full re-usability from the Services/Repositories layer.

On the front-end, you have a choice of:

- GWT for thick-client via RPC (return serialized Java object) or AJAX (return JSON)

- JSP, JSF, any templating available

- Mobile, Desktop, anything

Re:The Sun is Setting on Rails-style MVC Frameworks by rudy750 on Saturday February 25, 2012 @12:17PM (#3633329)
Can you tell me more? I am currently looking for a solution. Looking at jersery. What are you working with?
Re:The Sun is Setting on Rails-style MVC Frameworks by devs1010 on Sunday February 26, 2012 @02:39AM (#3635091)
look at spring roo, its a more modern approach and uses active record rather than the service layers / repositories, it makes generating json api's really simple
Re:The Sun is Setting on Rails-style MVC Frameworks by hello_moto on Sunday February 26, 2012 @05:52PM (#3637071)
A few points:

1) Spring Roo is not necessarily a more modern approach. It's more similar to Rails.

2) JAX-RS is more like Sinatra than Rails. Generating JSON api is already simple in JAX-RS.

3) Not everybody wants ActiveRecord

http://www.braintreepayments.com/devblog/untangle-domain-and...

https://github.com/braintree/curator#readme

4) JAX-RS comes with standard Java EE (moot point)

5) You can re-use your Servlet knowledge with JAX-RS to some extend (Filter, setting up web.xml, etc)

Not to take anything away from Spring Roo which is a wonderful project.

Re:The Sun is Setting on Rails-style MVC Frameworks by hello_moto on Sunday February 26, 2012 @01:52AM (#3635038)
I use jersey (provided by glassfish).
Re:The Sun is Setting on Rails-style MVC Frameworks by MatthewPhillips on Friday February 24, 2012 @02:50PM (#3630693)
I'd add that when you take this approach there is little reason your myapp.com endpoint needs to be anything more than a resource loader. Nginx + AppCache is all you really need to make your app load instantly with plenty of connections. Your API can, and probably should, set on a completely different server.
Re:The Sun is Setting on Rails-style MVC Frameworks by DodgyEggplant on Saturday February 25, 2012 @06:29AM (#3632729)
This also requires a different way to work w/ designers. I would love to get parts and chunks designed and delivered ready to inject to existent app (e.g. a js template) rather than the whole page/psd approach.
Re:The Sun is Setting on Rails-style MVC Frameworks by rolleiflex on Saturday February 25, 2012 @12:15PM (#3633320)
I am a designer and I already work that way, if I am not misunderstanding you.