How to use minified javascript?

江枫思渺然 提交于 2019-12-06 04:29:19

You could use usemin from https://www.npmjs.com/package/grunt-usemin. Usemin, with other tasks as

  • concat
  • uglify
  • cssmin
  • filerev

is able to minify all js and css in one single file. You only need to add a build:js as you can see in snippet below:

<!-- build:js SCLogic.min.js -->
        <!-- Load app main script -->
        <script src="app/app.js"></script>
        <!-- Load services -->
        <script src="app/services/authInterceptorService.js"></script>
        <script src="app/services/authService.js"></script>
        <script src="app/services/blablaService.js"></script>
       

        <!-- Load controllers -->
        <script src="app/controllers/indexController.js"></script>
        <script src="app/controllers/homeController.js"></script>
        <script src="app/controllers/loginController.js"></script>
        <script src="app/controllers/blablaController.js"></script>
        
        <script src="app/directives/validNumber.js"></script>
       
        <script src="app/controllers/angular-locale_es-es.js"></script>
       
        <!-- endbuild -->

You can just include the js file the normal way.

<script src="path to the minified file"></script>

in your index.html. Minified file is just like a normal JS file. What it does is:

  1. It will merge all the mentioned JS files into a single file.
  2. It will then minify it i.e it will remove the white spaces and auto change the variable names.
  3. Advantage of this is you will have a lower size file and a single http request made from your browser which will help you load the page at a faster speed.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!