如何在中包含带有查询字符串的 JS 文件?

发布于 2024-11-29 22:48:35 字数 393 浏览 0 评论 0原文

在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 技术交流群。

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

发布评论

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

评论(1

哎呦我呸! 2024-12-06 22:48:35

这是 Mojarra 中的一个错误。他们的 ScriptRenderer 按照问题 1212 修复以支持查询字符串。但是,对于指定的情况,他们的修复是错误的。他们使用 + 而不是 & 作为查询字符串参数分隔符,这只会导致 404:

<script src="/context/javax.faces.resource/reworkBase.js.xhtml?ln=js+version=1">

它应该是:

<script src="/context/javax.faces.resource/reworkBase.js.xhtml?ln=js&version=1">

我已将此错误报告为 问题 2168

与此同时,您最好的选择是完全省略 library ,因为您似乎对 js 的库名称(显然代表“JavaScript”)不感兴趣完全使用可配置的外观/脚本库。

<h:outputScript name="js/reworkBase.js?version=1" />

这将产生正确的 URL。

<script src="/context/javax.faces.resource/js/reworkBase.js.xhtml?version=1">

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 a library is specified. They used + instead of & as query string parameter separator, which only results in 404's:

<script src="/context/javax.faces.resource/reworkBase.js.xhtml?ln=js+version=1">

It should have been:

<script src="/context/javax.faces.resource/reworkBase.js.xhtml?ln=js&version=1">

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 of js (which obviously stands for "JavaScript") you seem not to be interested in using configureable look'n'feel/scripting libraries at all.

<h:outputScript name="js/reworkBase.js?version=1" />

This will result in the right URL.

<script src="/context/javax.faces.resource/js/reworkBase.js.xhtml?version=1">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文