【问题标题】:Is it possible to load all of AngularJS files (e.g. Controller, Factory) into an external HTML?是否可以将所有 AngularJS 文件(例如控制器、工厂)加载到外部 HTML 中?
【发布时间】:2015-09-04 02:48:47
【问题描述】:

我一直在构建一个应用程序,随着它的发展,<script> 标记也在index.html 中增长

index.html

<html>
    <head></head>
    <body>
        <script src="angular.js"></script>
        <script src="a.js"></script>
        <script src="b.js"></script>
        ...
    </body>
</html>

是否可以将所有这些&lt;script&gt; 包含到外部html 中,然后将其加载到index.html 中以使用它?像这样。

index.html

<html>
    <head></head>
    <body>

        <script src="angular.js"></script>

        [**Include jsInclude.html here**]
    </body>
</html>

jsIncude.html

<script src="a.js"></script>
<script src="b.js"></script>
...

如果是这样,执行此类任务的正确方法是什么?

我在网上看到我可以使用 Grunt 或 RequireJS 来动态加载 JS 文件。

但是,我希望避免延迟加载,我想在启动时一次加载所有 JS 文件。

使用 RequireJS 或 Grunt 能做到这一点吗?或者有其他方法可以实现吗?

【问题讨论】:

    标签: javascript html angularjs gruntjs requirejs


    【解决方案1】:

    你可以使用 webpack 或 browserify 将你所有的 JS 文件编译成 1 个 JS 文件。

    https://webpack.github.io/

    http://browserify.org/

    Grunt 只是一个任务运行器,它自己无法完成这项任务。你可以在 Grunt 中设置一个任务来运行 browserify/webpack

    【讨论】:

      【解决方案2】:

      是的,应该只是这样。首先加载 app.js,然后在你的 HTML (index.html) 中关注其他文件,包括控制器、工厂等

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-27
        • 2021-12-11
        • 2018-04-14
        • 1970-01-01
        • 2021-10-16
        • 1970-01-01
        • 1970-01-01
        • 2016-10-21
        相关资源
        最近更新 更多