如何在JSF页面中包含外部Javascript文件 [英] How to include external Javascript file in a JSF page

查看:94
本文介绍了如何在JSF页面中包含外部Javascript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想包含jQuery UI的URL http: //code.jquery.com/ui/1.9.0/jquery-ui.js .我看到很多问题,都说应该使用<h:outputScript>,但是在所有答案中,我都没有看到有关如何包含URL的示例.答案是?c0>"(?")............................................................................................................................................................................................................................................................仅当项目的某个文件夹中存在js文件时,答案才有意义.

I want to include the URL of jQuery UI http://code.jquery.com/ui/1.9.0/jquery-ui.js in my JSF page. I saw many questions which said <h:outputScript> should be used, but in none of the answers I saw an example as to how to include an URL. The answers were only relevant if the js file is present in some folder of the project.

有人可以帮我在页面上添加的地方吗?

Can someone please help where I have to include it in my page?

推荐答案

只需按常规方法使用纯HTML <script>元素即可.

Just use plain HTML <script> element the usual way.

<script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>

<h:outputScript>只能引用本地脚本.您只会错过它的动态版本控制,模块化和重定位优势,但是从技术上讲,这对于静态和外部脚本无害.

The <h:outputScript> can only refer local scripts. You'll only miss its dynamic versioning, modularity and relocation advantages, but that should technically not harm for a static and external script.

但是,可以使用自定义的ResourceHandler<h:outputScript>的URL更改为纯粹的CDN用途的外部URL. OmniFaces CDNResourceHandler 就是这样的示例.

It's however possible to use a custom ResourceHandler to change the URL of a <h:outputScript> to be an external URL for pure CDN purposes. OmniFaces CDNResourceHandler is such an example.

无关与具体问题无关,PrimeFaces组件是围绕jQuery/UI构建的.您是否完全肯定您需要一个单独的jQuery UI库实例?

Unrelated to the concrete problem, PrimeFaces components are built around jQuery/UI. Are you absolutely positive that you need a separate instance of jQuery UI library?

这篇关于如何在JSF页面中包含外部Javascript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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