自定义 Java Tapestry @IncludeStylesheet 注解

发布于 2024-10-13 01:07:09 字数 535 浏览 4 评论 0原文

使用 Tapestry 5,我正在寻找一种(如果可能的话)优雅的方式来自定义 @IncludeStylesheet 注释,以便自动将版本号添加到样式表文件名中。

例如,

  @IncludeStylesheet("context:/css/decoration.css")

将自动生成带有 v 版本号的 CSS 包含

  <link href="/css/decoration.css?v=12345" rel="stylesheet" type="text/css">

添加新注释,例如 @IncludeStylesheetVersion 是我最初的想法。
看看 Tapestry 代码,我似乎领先于一些代码复制/重构,以及 RenderSupportDocumentLinker (等等)的新实现。

是否有更简单的方法可以继续?

Using Tapestry 5, I'm looking at a (if possible) elegant way to customize the @IncludeStylesheet annotation in order to automatically add a version number to the style sheet file name.

For instance

  @IncludeStylesheet("context:/css/decoration.css")

would generate automatically the CSS inclusion with a version number

  <link href="/css/decoration.css?v=12345" rel="stylesheet" type="text/css">

Adding a new annotation, like @IncludeStylesheetVersion was my initial idea.
Looking at the Tapestry code, it looks like I'm ahead of some code copy / refactoring, with new implementations of RenderSupport and DocumentLinker (among others).

Would there be a simpler way to proceed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伪装你 2024-10-20 01:07:09

您可能根本不必这样做:资产版本控制内置于 Tapestry 中。根据文档,默认行为:

Tapestry 为资产创建新 URL
(无论是上下文还是类路径)。这
URL 的格式为 /assets/application
版本号/文件夹/路径

  • 应用程序版本号:由符号tapestry.application-version定义,默认值为随机的十六进制数。

如果您只需要确保客户端在更新后看到更改后的样式表并且您不会一直重新启动应用程序,那么默认行为(随机十六进制数)应该就可以了。

根据评论进行编辑:5.1 中也提供< /a>:

  • app/app-version(适用于在以下版本或以下版本获得的资产)
    应用程序包)
  • classpath/app-version(适用于从任何其他方式获取的资产
    未映射的包)

其中 version 是 Tapestry 框架版本,app-version 是应用程序版本(如果没有显式配置,它将是一个随机字符串)。

只需检查 Tapestry 为您的 CSS 文件生成的 URL,它们应该如下所示:http://myserver.com/assets/ctx/942f15f778dca26c/css/styles.css

You may not have to do that at all: Asset versioning is built into Tapestry. The default behaviour, according to the 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.

If you just need to make sure clients will see changed stylesheets after an update and you don't restart your app all the time, the default behavior (random hex number) should do just fine.

Edit based on comment: This is also 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).

Just check the URLs Tapestry generates for your CSS files, they should look like this: http://myserver.com/assets/ctx/942f15f778dca26c/css/styles.css

还如梦归 2024-10-20 01:07:09

总体而言,您在升级到 5.3 上投入的精力可能比尝试创建注释来模仿当前版本的内置功能更划算。我认为您会发现升级过程非常轻松——特别是如果您有良好的集成测试。

Overall, the effort you'd put into upgrading to 5.3 will probably be better spent than trying to create an annotation to mimic the built in functionality of current versions. I think you'll find the upgrade process pretty painless--particularly if you have good integration testing in place.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文