single-page applications and grails
DESCRIPTION
Talk about how to deal with Single-page applications and GrailsTRANSCRIPT
SINGLE-PAGE APPLICATIONS &
GRAILS
Álvaro Sánchez-Mariscal
About me
Passionate software developer. Founder & CEO of Salenda and Escuela
de Groovy. Groovy/Grails lover since 2007.
Typical Grails architecture Grails is an MVC, where:
Model is implemented using POGO’s for GORM (Hibernate).
Views are rendered on the server side using GSP’s and taglibs.
Controllers are Groovy classes with methods as actions.
So what the hell is a SPI application?
A SPI web app is…
A web application where you can navigate without any page refresh.
REST is used to communicate with the server.
The MVC is in the browser, written in Javascript, where:The model are Javascript classes.The views are written in HTML.The controller, services, etc. are also written in
Javascript.
Did you say Javascript?!?
Really?!?
WTF!
WTF!
Some people like Javascript
And why the hell should I
care about SPI?
Because it has some advantages It’s faster, because:
Modern browsers have faster Javascript engines.
Only the data is sent, not the full markup. It has a better user experience,
because:Data refreshes instantly.
It may be easier for the developer:If you choose the right framework, you don’t
have to deal with events or callbacks.
But, it also has some cons What happens if there is no Javascript?
Are you going to gracefully degrade? How do we deal with server
communication failures? Can I still use the application without an
Internet connection? Am I going to replicate the MVC in the
client? Again? In Javascript?
Ok. And how do I implement it using Grails?
Less server logic
Your Grails application gets simplified. Just use GORM (or any other backend)
with a REST API.Implementing a REST API with Grails is
really easy. Just focus on:
Transactions.Data retrieving and storing.Security / authentication.Scalability
And do I really need a Grails application for
that?
Not really
You can use Vert.x. Or if you want to be really cool, use
Node.js. Even if you are really bored, you can
just do it in Java…
News from this morning
In Grails 3.0 you will have application profiles:Servlet “classic” profile.Lightweight profile.REST profile.
Ok with the server side. What can I do with the
client?
There’s lot of frameworks
Comprehensive comparision Todo MVC, by Addy Osmani
and Sindre Sorhus.
http://addyosmani.github.com/todomvc/
Similar features
Models.Domain classes.
Views and templates.GSP’s and templates.
{{ }}${}
Controllers. Routing.
URL Mappings.
}
Gotchas
Are views on the client really the best option? What about….?i18n?Security?Caching?
How do we handle dependency management in our Javascript code?
…
Show me some code please!
That’s all!Thanks!
Álvaro Sánchez-Mariscal@alvaro_sanchez