在html文件的一行中引用多个js文件 [英] reference multiple js files in a single line in a html file

查看:64
本文介绍了在html文件的一行中引用多个js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法来引用HTML文件中的所有js文件,而不是一个一个地引用它?

Is there an easy way to reference all js files in an HTML file rather than referencing it one by one?

代替这个-

<script type="text/javascript" src="js/controllers/mainCtrl.js"></script>
<script type="text/javascript" src="js/controllers/browseCtrl.js"></script>
...

我正在寻找类似的东西-

I'm looking for something like this -

<script type="text/javascript" src="js/controllers/*.js"></script>

还是那里提供了一种工具,可以将这些文件的内容复制到一个文件中,然后引用该文件?这将最大程度地减少HTTP调用.

Or is there a tool out there that copies the contents of these files into one file and reference that one file instead? This will be minimize the HTTP calls.

推荐答案

是否有一种简单的方法来引用HTML文件中的所有js文件,而不是一个一个地引用它?

Is there an easy way to reference all js files in an HTML file rather than referencing it one by one?

具有一些简单"的价值.浏览器没有内置的功能可以做到这一点.

For some value of "easy". There is nothing built in to browsers that will do it though.

还是那里提供了一种工具,可以将这些文件的内容复制到一个文件中,然后引用该文件?

Or is there a tool out there that copies the contents of these files into one file and reference that one file instead?

有很多. cat 是最简单的猫.

There are many. cat is the simplest one.

从您通常的构建工具中调用它.

Call it from your usual build tool.

您可以使用 require.js 之类的东西在开发期间的运行时将它们组合起来,然后调用 r.js (通过构建工具中的Node通过Node打包)以用于临时和现场环境.

You can use something like require.js to combine them at runtime during development, and call r.js via Node from your build tool for packaging for your staging and live environments.

这篇关于在html文件的一行中引用多个js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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