如何使用 JSF outputStylesheet 实现 CSS 缓存清除?
在 JSF 页面模板中,我使用此代码来包含 CSS 资源:
<h:outputStylesheet library="css" name="mystyles.css" />
实现 CSS 缓存清除的常用方法是添加版本参数,例如 v=123
,但是 outputStyleSheet 不支持此操作:
<h:outputStylesheet library="css" name="mystyles.css?v=123" />
将导致 JSF1064 警告并且将找不到 CSS。
In JSF page templates I use this code to include a CSS resource:
<h:outputStylesheet library="css" name="mystyles.css" />
The usual way to implement CSS cache busting would be to add a version parameter, like v=123
, however this is not supported in outputStyleSheet:
<h:outputStylesheet library="css" name="mystyles.css?v=123" />
will cause a JSF1064 warning and the CSS will not be found.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不重写
StylesheetRenderer
(假设您使用的是 Mojarra),这是不可能的。它确实没有考虑查询字符串。但是,作为(临时)解决方法,最好知道在
内使用 CSS 自己的@import
规则包含 CSS 是有效的。您可能需要向 Mojarra 男孩发布增强请求,以便在未来的版本中考虑到这一点。
That's not possible without overridding the
StylesheetRenderer
(assuming you're on Mojarra). It does indeed not take the query string into account. However, as a (temporary) workaround it's good to know that it is valid to include the CSS using CSS' own@import
rule inside<h:outputStyleSheet>
.You might want to post an enhancement request to the Mojarra boys to take this into account in future releases.