Book Image

Learning Play! Framework 2

By : Andy Petrella
Book Image

Learning Play! Framework 2

By: Andy Petrella

Overview of this book

<p>The Learning Play! Framework 2 has been created for web developers that are building web applications. The core idea is to focus on the HTTP features and to enable them through a simplification lens. Building a web application no longer requires a configuration phase, an environment setup, or a long development lifecycle - it's integrated!<br /><br />Learning Play! Framework 2 will enable any web developers to create amazing web applications taking advantage of the coolest features. It's the fastest way to dive into Play!, focusing on the capabilities by using them in a sample application. Although essentially Java based code, a Scala version is presented as well – giving an opportunity to see some Scala in action.<br /><br />After setting up the machine and learning some Scala, you will construct an application which builds from static to dynamic, before introducing a database. <br /><br />Then we'll focus on how data can be consumed and rendered in several ways. This will enable some real time communication through WebSocket and Server-Sent Event – on both server and client sides.</p> <p>The book will end with testing and deployment, which completes any web development project.</p>
Table of Contents (20 chapters)
Learning Play! Framework 2
Credits
About the Author
Acknowledgement
About the Reviewers
www.packtpub.com
Preface
Materials
Index

What's new?


The following sections will be dedicated to what comes with this new version of Play! that wasn't available in the first version.

Scala

As said earlier, this version has been built using Scala as the core language, whereas Play! 1 uses the Java language and provides support for Scala.

Simple Build Tool

But that's not all! One of the biggest changes of Play! 2 is its console. Indeed, Play! 1's console was a custom one, using Python to reduce the memory footprint and the need to start a JVM all the time. This has been revoked in Play! 2 because of Simple Build Tool (SBT). This build tool has the disadvantage of starting a JVM but, you'll start it only once! This is because the SBT console is a "real" console as it provides commands, tasks, and so on.

Furthermore, SBT is easily extensible and that's exactly what has been done for Play! to enable or customize specific actions for it (such as run).

Templates

In this new version, where Scala was chosen as the core language, the Play! Framework 2 team has also chosen Scala for server-side rendering. This means that they have built a brand new templating system that uses Scala rather than Groovy in the first version.

However, they didn't use Scala as just an empty language to generate HTML (for instance); rather, they integrated the generated page (or data) with Scala. And how did they accomplish that? By producing a regular Scala file that will be compiled. Hence, writing a template is type safe; they can be composed easily and have a steep learning curve.

Assets

A web application will always come with assets that are meant to be served as is by the server. However, those assets will be optimized by Play! for us, by precompiling them or by using an HTTP mechanism to reduce the server's work to serve them. One example is to use the ETag header to avoid resending the same thing again and again.

That was for performance, but Play! has been created by web developers, and only they know what other problems they had with assets such as JavaScript and CSS. That's why a new feature that comes for free with Play! 2 is the ability to write compiled assets such as a CoffeeScript file for JavaScript or LESS CSS for CSS, without any configuration or additional tasks when starting to work.

The integration of these languages has been done deeply, so their compilation errors are shown to the developers like it is for a classical "server" code, which is on the browser!