根据前一篇文章的实现思路写了这个插件,并放到了github,有需要的朋友请自行下载使用。
http://github.com/roymax/play-cdn {将不再维护和准备关闭了}
Notes: 从Play! 1.1开始已经华丽地通过修改route原生支持CDN部署。
在route中修改原来的静态资源映射如下
在引用资源的时候使用@@{} 而不是默认的@{}标签,如
<link rel="stylesheet" type="text/css" media="screen,projection" href="@@{'/public/stylesheets/style.css'}">
以上代码能够在开发环境与部署环境中完美地自动切换。
具体看这里的 , http://www.playframework.org/documentation/1.1RC1/releasenotes-1.1
The routes file now supports Host matching. this can be useful if action parameters must be extracted from the host parameter. For example, for a SAAS application, you could use:
Virtual hosting in routes
and then automatically retrieve the client value as for any other request parameter:
When using the @@{…} notation (absolute reverse routing) in a template, the host will be used if provided by the corresponding route. This can be useful in several situations.
For example, if you want to use a content distribution network to distribute your static assets in production, you could write a routes file like this:
And in your templates:
This will be reversed as http://locahost:9000/public/images/logo.png in DEV mode, andhttp://assets.myapp.com/images/logo.png in PROD mode.