使用 Tapestry 5,我正在寻找一种(如果可能的话)优雅的方式来自定义 @IncludeStylesheet
注释,以便自动将版本号添加到样式表文件名。
例如
@IncludeStylesheet("context:/css/decoration.css")
会自动生成带有版本
版本号的 CSS 包含
<link href="/css/decoration.css?v=12345" rel="stylesheet" type="text/css">
添加一个新的注释,比如 @IncludeStylesheetVersion
是我最初的想法。
查看 Tapestry 代码,我似乎领先于一些代码复制/重构,以及 RenderSupport
和 DocumentLinker
(以及其他)的新实现。
是否有更简单的方法进行?
最佳答案
您可能根本不需要这样做: Assets 版本控制内置于 Tapestry 中。默认行为,根据 docs :
Tapestry creates a new URL for assets (whether context or classpath). The URL is of the form
/assets/application version number/folder/path
.
- application version number: Defined by symbol
tapestry.application-version
, the default value is a random hex number.
如果您只需要确保客户端在更新后会看到更改后的样式表并且您不会一直重启您的应用程序,那么默认行为(随机十六进制数)应该就可以了。
根据评论编辑:这也是 available in 5.1 :
- app/app-version (for assets obtained at or beneath the application package)
- classpath/app-version (for assets obtained from any otherwise
unmapped package)Where version is the Tapestry framework version, and app-version is the application version (which will be a random string if not explicitly configured).
只需检查 Tapestry 为您的 CSS 文件生成的 URL,它们应该如下所示:http://myserver.com/assets/ctx/942f15f778dca26c/css/styles.css
关于java - 自定义 Java Tapestry @IncludeStylesheet 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4756618/