如何在中包含带有查询字符串的 JS 文件?
在JSF页面中,我使用这段代码包含一个JS文件:
<h:outputScript library="js" name="reworkBase.js" />
它工作得很好,但我想通过添加版本参数来实现缓存清除:
<h:outputScript library="js" name="reworkBase.js?version=1" />
但是找不到JS文件。我知道如果我使用 标签,它也能很好地工作。但是有没有办法用
标签来实现呢?
In JSF page I use this code to include a JS file:
<h:outputScript library="js" name="reworkBase.js" />
It works well, but I want to implement cache busting by adding a version parameter:
<h:outputScript library="js" name="reworkBase.js?version=1" />
But the JS file will not be found. I know it also works well if I use the <script type="text/javascript">
tag. But is there any way to implement with <h:outputScript>
tag?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 Mojarra 中的一个错误。他们的
ScriptRenderer
按照问题 1212 修复以支持查询字符串。但是,对于指定库
的情况,他们的修复是错误的。他们使用+
而不是&
作为查询字符串参数分隔符,这只会导致 404:它应该是:
我已将此错误报告为 问题 2168。
与此同时,您最好的选择是完全省略
library
,因为您似乎对js
的库名称(显然代表“JavaScript”)不感兴趣完全使用可配置的外观/脚本库。这将产生正确的 URL。
That's a bug in Mojarra. Their
ScriptRenderer
was as per issue 1212 fixed to support query strings. However, their fix was wrong for the case alibrary
is specified. They used+
instead of&
as query string parameter separator, which only results in 404's:It should have been:
I've reported this bug as issue 2168.
In the meanwhile your best bet is to just omit the
library
altogether, given the library name ofjs
(which obviously stands for "JavaScript") you seem not to be interested in using configureable look'n'feel/scripting libraries at all.This will result in the right URL.