如何在Play 2.3.4中设置资产指纹识别? [英] How to set up asset fingerprinting in Play 2.3.4?
问题描述
版本:
- 播放2.3.4
- sbt 0.13.1
- scala 2.11.2
我已遵循playframework.com上的文档来启用指纹识别功能公共资产,但调用routes.Assets.versioned
绝不会产生带有摘要哈希的版本化文件名.
I've followed the documentation on playframework.com to enable fingerprinting on public assets, but calls to routes.Assets.versioned
never produce a versioned filename with a digest hash.
build.sbt中的相关行:
Relevant lines in build.sbt:
scalaVersion := "2.11.2"
pipelineStages := Seq(rjs, digest)
project/plugins.sbt中的相关行:
Relevant lines in project/plugins.sbt:
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.4")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.5")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.0.0")
conf/routes中的相关行:
Relevant lines in conf/routes:
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
以及主模板:
@(title: String, lang: String, cssClasses: String, bodyContents: Html)
<!DOCTYPE html>
<html lang="@lang">
<head>
<meta charset="UTF-8">
<title>@title</title>
<script type="text/javascript" src="@routes.Assets.versioned("javascript/components/main.js")"></script>
</head>
<body>
<div class="layout @cssClasses">
@bodyContents
</div>
</body>
</html>
输出始终为:
<!DOCTYPE html>
<html lang="el">
<head>
<meta charset="UTF-8">
<title>[title]</title>
<script type="text/javascript" src="/assets/javascript/components/main.js"></script>
</head>
<body>
...
</body>
</html>
我没有得到编译器错误.指纹只是不起作用".我以为我缺少一些简单的东西,但是看不到.
I get no compiler errors. The fingerprinting just "doesn't work". I assume I am missing something simple, but I cannot see it.
其他说明:
-
正如文档所建议的那样,在项目根目录中运行
- 运行
find . -name "*.js"
时,没有显示摘要开头的文件 - 我已经运行
sbt clean dist
来生成生产模式版本,并且行为相同
- running
find . -name "*.js"
in the root of the project shows no files that have a digest appended to the beginning, as the documentation suggests - I've run
sbt clean dist
to generate a production mode release and the behavior is the same
有人可以建议吗?
谢谢!
注意:我已经开始浏览target/src_managed/main/routes_reverseRouting.scala
中生成的类以调试生成的versioned
方法,但是对于相当简单的东西来说这似乎有些过分了.
NB: I've started looking through the generated class in target/src_managed/main/routes_reverseRouting.scala
to debug the generated versioned
method, but this seems like overkill for something that is fairly straightforward.
推荐答案
据我记得,几周前我遇到了同样的问题.将资产路线更改为:
As far as I can remember I had the same problem a couple of weeks ago. Change the asset route to:
GET /web/assets/*file controllers.Assets.versioned(path="/public", file:Asset)
(请参阅"file:Asset
"-如果我没记错的话,似乎需要"Asset
")
(See the "file:Asset
" - it seems that "Asset
" is required if I remember correctly)
这篇关于如何在Play 2.3.4中设置资产指纹识别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!