Search code examples
javascriptangularjsinternet-explorer-8gulpgulp-uglify

How to minify angular.js?


There is a problem,i want to minify the angular.js, not my personal code but the angular library file --angular.js, I used gulp-uglify to minify it , here is the gulp code:

gulp.task('angularjsmin', function () {
gulp.src(['lib/angular/angular.js']) 
    .pipe(uglify())
    .pipe(contact("angular.min.js"))
    .pipe(gulp.dest('dist/lib/angular'));

});

It worked in morden browser , but it's unuse in IE8. The angular version is 1.2.29, it's support IE8, but the file "angular.min.js" which i minified is not support IE8, and when use it in IE8,the browser tell me that "Missing identify" and "angular is undefined". Is there any other methods to minify the angular.js? How can i solve this problem?Thanks for your help.


Solution

  • Use a CDN in order to delivery common libraries like angular or jquery, you will avoid possible headache of build it yourself. If you do not have a specific reasons and advantage to do so, a CDN is the good way to go.

    Some major libraries are hosted on CDN for free on very reliable servers like Google offers:

    https://developers.google.com/speed/libraries/

    and you can simply include the library in your code as:

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>

    The main advantage of a CDN is an increase in the speed on which the content is delivered to the users.

    Some advantages are:

    • Lower server load.
    • Increase in concurrent users on server.
    • Geo-location.
    • User may have already downloaded the library (cached previously in browser).

    But if you really want to build yourself try reading the following tutorial: https://docs.angularjs.org/misc/contribute