在< script>的src属性中使用通配符标签? [英] Use wildcard in src attribute of <script> tag?

查看:123
本文介绍了在< script>的src属性中使用通配符标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,愚蠢的问题,我不认为这是可能的,但是,我的.aspx页面顶部有这个标记......

Ok, stupid question and I don't think it's possible but, I have this markup at the top of my .aspx page...

<%--Third Party Libraries, Plugins, Extensions --%>
<script src="Libraries/Raphael/Raphael.js" type="text/javascript"></script>
<script src="AutoComplete/jquery.autocomplete.js" type="text/javascript"></script>    
<script src="Libraries/jQuery/1.4.2/jquery.js" type="text/javascript"></script>
<script src="Libraries/jQuery/UI/1.8.4/jquery.ui.core.js" type="text/javascript"></script>
<script src="Libraries/jQuery/UI/1.8.4/jquery.ui.widget.js" type="text/javascript"></script>
<script src="Libraries/jQuery/UI/1.8.4/jquery.ui.mouse.js" type="text/javascript"></script>
<script src="Libraries/jQuery/UI/1.8.4/jquery.ui.draggable.js" type="text/javascript"></script>
<script src="Libraries/jQuery/UI/1.8.4/jquery.ui.droppable.js" type="text/javascript"></script>    

如果我能用这个代替它,那会不会很好......

Wouldn't it be nice if I could replace that with this...

<%--Third Party Libraries, Plugins, Extensions --%>
<script src="Libraries/Raphael/Raphael.js" type="text/javascript"></script>
<script src="AutoComplete/jquery.autocomplete.js" type="text/javascript"></script>    
<script src="Libraries/jQuery/1.4.2/jquery.js" type="text/javascript"></script>
<script src="Libraries/jQuery/UI/1.8.4/jquery.ui.*.js" type="text/javascript"></script>

即使用 * 作为通配符。

显然,这是JS,我可以将所有这些脚本放入一个大脚本并加载,但我真的不喜欢这样做。

Obviously as this is JS I could just throw all those scripts into one big script and load that but I don't really fancy doing that.

其他人有整理大量脚本参考的技巧吗?或者我们只是忍受它?

Anyone else have a technique for tidying up masses of script refs? Or do we just live with it?

推荐答案

据我所知,这是不可能的,因为浏览器需要准确知道要请求的文件。

As far as I know this is not possible, simply because, the browser would need to know exactly what files to request.

浏览器基本上必须使用希望获得幸运的请求来强制您的服务器。

The browser would essentially have to brute force your server with requests hoping to get lucky.

我是建议使用Google的闭包编译器将所有类似的(如果不是全部)javascript文件合并到一个文件中。它会略大,但会减少http请求。

I'd suggest using Google's closure compiler to merge all similar, if not all, javascript files into a single file. It will be slightly large, but would cut down on http request.

通过一些分析,您可以找到最常用的文件和速度之间的平衡。

With some profiling you could find a balance between which files are needed most commonly and speed.

更新(来自评论)

我一般不愿意提供添加新的javascript库来解决发布了太多的javascript库:)此外,这似乎是更直接的解决方案。目前我们使用Google封闭API来压缩和合并我们所有的javascript和CSS,并使用ANT构建时间。有魅力。这也可以在某种程度上直接使用apache2虚拟主机/ htaccess(请参阅html5boilerplate.com)获取示例和限制

I'm generally reluctant to offer adding a new javascript library to solve the issue of too many javascript libraries :) Plus this just seemed like the more straight forward solution. Current we use the Google closure API to compress and merge all our javascript and CSS and build time with ANT. Works a charm. This can also be done to some extent direct with apache2 virtual host/htaccess (see html5boilerplate.com) for examples and limitations

这篇关于在&lt; script&gt;的src属性中使用通配符标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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