加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – CDN在Play 2.0上使用

发布时间:2020-12-16 18:38:01 所属栏目:安全 来源:网络整理
导读:我有一个拥有大量静态内容的高流量网站.它目前在Play 1.2.4上,但我正在迁移到Play 2.0.2. 对于Play 1.X,我们编写了一些代码,而不是html模板中的@asset. /** * Drop-in replacement for @asset. Use to take advantage of cloudfront on live. * Paths are al
我有一个拥有大量静态内容的高流量网站.它目前在Play 1.2.4上,但我正在迁移到Play 2.0.2.

对于Play 1.X,我们编写了一些代码,而不是html模板中的@asset.

/**
 * Drop-in replacement for @asset. Use to take advantage of cloudfront on live.
 * Paths are always absolute to root. Leading '/' is optional.
 *
 * @param path relative to the application root. This should usually be "public/some-file"
 * @return path to asset on the currently configured CDN.
 */
def cdnAsset(path: String) : String = {
  cdnEnabled match {
    case "true" =>
      path(0) match {
        case '/' => "https://" + cdnUrl + path
        case _ =>  "https://" + cdnUrl + "/" + path
      }

    case _ =>
        play.mvc.Router.reverse(play.Play.getVirtualFile(path))
  }
}

对于Play 2.0,我认为我们可以改进这一点.我认为如果我们不必使用我们的自定义代码而不是使用Play 2.0提供的@ Asset.at来丢弃我们的模板会更好.我不确定最好的方法.我想知道在Play 1.2.X上回答这个问题时是否做了类似的事情
Hosting static HTML in a Play! app on CloudFront
可以为Play 2.0完成.

我想充分利用Play 2.0提供的Assets控制器,因为它执行了一些很好的优化.

有谁知道这样做的方法?我想是否可以用一些路由器魔法来完成,这将是理想的,但我仍然有点太初学的Play,知道是否或如何可能.

解决方法

詹姆斯沃德写了一个 excellent tutorial干净利落地做.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读