Book Image

Play Framework essentials

By : Julien Richard-Foy
Book Image

Play Framework essentials

By: Julien Richard-Foy

Overview of this book

This book targets Java and Scala developers who already have some experience in web development and who want to master Play framework quickly and efficiently. This book assumes you have a good level of knowledge and understanding of efficient Java and Scala code.
Table of Contents (9 chapters)
8
Index

Serving static assets

The web layer we wrote in the previous chapter was not really complete; we could add some beautiful CSS styles and some cool JavaScript behavior. CSS files, JavaScript files, as well as images do not change once your application is started, so they are usually referred to as static assets. The most convenient way to serve them is to map a URL path to a directory of your filesystem. Play comes with an Assets controller that does just this. Consider the following route definition:

GET   /assets/*file   controllers.Assets.at(path = "/public",   file)

This route maps the public directory of your application to the assets path of your HTTP layer. This means that, for example, a public/stylesheets/shop.css file is served under the /assets/stylesheets/shop.css URL.

This works because Play automatically adds the public/ directory of your application to the classpath. To use an additional directory as an assets folder, you have to explicitly add it to the application...