【问题标题】:Any nice way to handle lots of external JS file in Html page? [duplicate]在 Html 页面中处理大量外部 JS 文件的任何好方法? [复制]
【发布时间】:2015-03-31 17:52:37
【问题描述】:

考虑以下

<html ng-app="crudModule">
@{
    ViewBag.Title = "Index";
}

<body ng-controller="crudController">
    <table id="tblContainer" border="1">
        <thead>
            <tr>
                <th>EmpName</th>                
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="emp in Employees" my-employee="emp"></tr>
        </tbody>
    </table>
    <script type="text/ng-template" id="Employee.html">
        <tr>
            <td> <span>{{_employee.EmployeeId}}</span></td>            
        </tr>
    </script>   
</body>
</html>
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-route.js"></script>
<script src="~/Scripts/MyScripts/Module.js"></script>
<script src="~/Scripts/MyScripts/Service.js"></script>
<script src="~/Scripts/MyScripts/Controller.js"></script>
<script src="~/Scripts/MyScripts/Builder.js"></script>
<script src="~/Scripts/MyScripts/Utility.js"></script>

同一页面中有很多外部 javascript 文件。

有没有什么好的方法可以让页面只有一个 JS 文件,而其他的都在那个里面或任何其他方式?

【问题讨论】:

  • 您可以使用grunt-contrib-concat 之类的服务。首先你需要安装node,然后是grunt,但是这样做的好处是巨大的。
  • 查看 requirejs @ requirejs.org - 我从未使用过它,但它听起来像你要找的东西

标签: javascript


【解决方案1】:

这是asp.net/mvc使用脚本捆绑。见

http://www.asp.net/mvc/overview/performance/bundling-and-minification

谢谢

【讨论】:

  • 注意,如果不是示例中的 MVC 代码,我不会建议这样做。当您使用 MVC 时,利用它的框架并没有错。
猜你喜欢
  • 2011-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-12
  • 1970-01-01
  • 1970-01-01
  • 2021-06-28
相关资源
最近更新 更多