O'Reilly logo

Play Framework Essentials by Julien Richard-Foy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required