在Play框架中提供的都是动态文件响应,前端工做内容大部分是静态文件.Assets大概起的就是这个做用.html
默认路径看 conf/routes 里:前端
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
#注释大意是静态文件从 /public 文件夹到 /assets 中URL路径.java
规则声明HTTP GET请求 /assets/ 时映射到 Controllers.Assets.at 方法,该方法使用两个参数,告诉该方法 Path 路径和 file 文件.windows
缺省使用 /public/filename 路径,若是须要指定详细点,能够定义路由规则:缓存
GET /images/*file controllers.Assets.at(path="/public/images", file)
GET /styles/*file controllers.Assets.at(path="/public/styles", file)
使用assets逆向路由来避免hardocded(硬编码[百度百科词条])的URL,Assets.at也是一个普通的Action方法,所以你能够使用assets逆向路由,例如:ruby
<link href="@routes.Assets.at("images/favicon.png")" rel="shortcut icon" type="image/png">
除了逆向路由的优势,使用Asset控制器的另一个优势是内置的缓存支持以及和Http Entity Tag(Etag)的支持.从而容许客户端根据须要是否要从服务器请求资源仍是能够使用Cached中的文件.服务器
Assets这个从rails中发展出来的,能够看看[Ruby-China]中的介绍.oracle