如何在< h:outputScript>中包含带有查询字符串的JS文件? [英] How can I include a JS file with query string in <h:outputScript>?

查看:162
本文介绍了如何在< h:outputScript>中包含带有查询字符串的JS文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JSF页面中,我使用以下代码包括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" />

但是找不到JS文件.我知道如果使用<script type="text/javascript">标记,它也可以很好地工作.但是,有什么方法可以使用<h:outputScript>标签实现吗?

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?

推荐答案

这是Mojarra中的错误.他们的ScriptRenderer根据问题1212 进行了修改,以支持查询字符串.但是,对于指定library的情况,其修复是错误的.他们使用+而不是&amp;作为查询字符串参数分隔符,这仅导致404:

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 &amp; as query string parameter separator, which only results in 404's:

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

应该是:

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

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

同时,最好的选择是完全省略library,给定库名js(显然代表"JavaScript"),您似乎对使用可配置外观没有兴趣/脚本库.

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" />

这将产生正确的URL.

This will result in the right URL.

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

这篇关于如何在&lt; h:outputScript&gt;中包含带有查询字符串的JS文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆