angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

vendor.********.bundle.js size is too large in production

Open AungMyoKyaw opened this issue 9 years ago • 29 comments

OS?

Mac OSX (Yosemite)

Versions.

1.0.0-beta.24

My App Repo

https://github.com/AungMyoKyaw/NightlifeCoordinationApp

ng build --prod --aot vendor.**.bundle.js size is still too large. angular-cli compress this file for production but it does not remove comment. is there options for this ? please

AungMyoKyaw avatar Jan 17 '17 04:01 AungMyoKyaw

No there is currently no option to remove comments. This has been up for discussion but has to run through the legal team before being implemented.

I did a test where I removed comments from the *.js files. It only saved 1-2kb anyhow.

Edit: See https://github.com/angular/angular-cli/issues/3270#issuecomment-262840303

grizzm0 avatar Jan 17 '17 10:01 grizzm0

124k gzipped is about right for the vendor bundle that includes Core, Router, Forms, and Http modules. If this issue is about the overall size of the Angular project I believe it is something the core team is working on.

deebloo avatar Jan 17 '17 12:01 deebloo

Closed as answered.

filipesilva avatar Jan 17 '17 12:01 filipesilva

@deebloo , I got gzipped size similar to 124k for a fresh angular-cli generated app. But from angular.io aot section, they have a chart stating total bundle size 269k(not gzipped), while the fresh angular-cli gives 421k(not gzipped) for vendor.bundle with ng build --prod --aot --sm, as in this chart. Any idea why 50% more bigger?

rxjs-space avatar Jan 19 '17 10:01 rxjs-space

@rxjs-space have not read the article. does it include zone.js and polyfills with that bundle? also a freshly genrated cli app includes more then just core. Also that example is using rollup where the cli uses webpack. (and I believe the rollup treeshaking algo is better then webpack atm)

deebloo avatar Jan 19 '17 13:01 deebloo

@deebloo , no, zone.js and polyfills are not included in the smaller bundle. If we only compare the package '@angular/core', the difference is still significant, that is 57k vs 135k. You may find more details through the chart links in my last comment.

rxjs-space avatar Jan 19 '17 13:01 rxjs-space

Here is a screenshot of a hello world with no polyfills (other then zone.js and reflect), and only using angulars core module. It is much closer to 57k. I agree that size is a major factor and still an issue the angular team should address. removing zonejs from that bundle would get you another 13k or so

screen shot 2017-01-19 at 9 27 26 am

deebloo avatar Jan 19 '17 14:01 deebloo

@rxjs-space would be happy to share the app code for this hello world, but should move to a different platform since this issue is closed

deebloo avatar Jan 19 '17 14:01 deebloo

@deebloo , It's amazing that you get a vendor bundle at 313k(unzipped) or 71k(gzipped). I'd be grateful to have the app code. Please advise how you would like to share it.

rxjs-space avatar Jan 20 '17 00:01 rxjs-space

I'll share when I am back at a computer. This is just for hello world so as you add the router, http, etc it will grow

deebloo avatar Jan 20 '17 01:01 deebloo

// app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  bootstrap: [AppComponent]
})
export class AppModule { }
// app.component.ts
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `
    <h1>Hello World</h1>
  `
})
export class AppComponent { }
// polyfills.ts
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';

deebloo avatar Jan 20 '17 14:01 deebloo

@deebloo , thanks for the code. With your code, I got similar result as yours -- vendor.bundle size 308k unzipped and 70k gzipped. That is quite good. Here's the breakdown. But with source-map-explorer, for @angular/core, the result is still 135k, where in angular doc's aot section, it is 57k. Maybe the size diff is caused by different bundle system, angular doc used rollup. I have not used rollup and will try it out soon.

rxjs-space avatar Jan 20 '17 15:01 rxjs-space

@deebloo, With John Papa's toh repo(which used rollup), I can have a build.js with @angular/core at 72k for a toh app (here's the detail), while angular-cli gives a 135k @angular/core for bare hello world. I think we may need to start a new issue for this.

rxjs-space avatar Jan 20 '17 15:01 rxjs-space

I have noticed that a small app I built would get me 7xxk of main.bundle using beta 26 with AOT enabled. Seems quite huge to me.

itsnotvalid avatar Jan 25 '17 05:01 itsnotvalid

@itsnotvalid : same issue.. Its basically a new project created with the cli. I imported just the angular-jwt. But this would not explain the 500kb more.

The question is: I have many entries in my polyfills.ts. Do I need that many and do they have that high impact on the size?

My discoveries:

  1. Removing blanks and line breaks and comments in the vendor.***.bundle.js will save ~40kb (729922 bytes to 687178 bytes) with --prod and --aot
  2. I removed some polyfill.js entries which saved me like ~32kb (729922 bytes to 698000 bytes)
import 'core-js/es6/object';
import 'core-js/es6/function';
//import 'core-js/es6/parse-int';
//import 'core-js/es6/parse-float';
//import 'core-js/es6/number';
//import 'core-js/es6/math';
import 'core-js/es6/string';
//import 'core-js/es6/date';
//import 'core-js/es6/array';
//import 'core-js/es6/regexp';
import 'core-js/es6/map';
//import 'core-js/es6/set';
import 'core-js/es6/reflect';

import 'core-js/es7/reflect';
import 'zone.js/dist/zone';

I probably can remove some more because I think Im just using the string, function, object and map. Edit: I removed everything but import 'core-js/es7/reflect'; import 'zone.js/dist/zone'; saved me additional 9KB. I expected more tbh.. 3. I removed ReactiveFormsModule, because I was not using it anyway. Saved me 0kb somehow?

My actual app.component.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { Http, HttpModule, RequestOptions } from '@angular/http';
import { AuthHttp, AuthConfig } from 'angular2-jwt';

import { AppComponent } from './app.component';

import {Config} from "./config";

import { LoginComponent } from "./unprotected/login.component";
import { ProtectedComponent } from "./protected/protected.component";

import { routing } from "./app.routing";


import { Auth } from "./auth.service";
import { AuthGuard } from "./auth-guard.service";

export function authHttpServiceFactory(http: Http, options: RequestOptions) {
  return new AuthHttp(new AuthConfig({
          tokenName: 'id_token',
          tokenGetter: (() => localStorage.getItem('id_token')),
          globalHeaders: [{'Content-Type':'application/json'}],
     }), http, options);
}


@NgModule({
  declarations: [
    AppComponent,
    LoginComponent,
    ProtectedComponent,
  ],
  imports: [
    BrowserModule,
    HttpModule,
    routing,
  ],
  
  providers: [
    Config,
    Auth,
    AuthGuard,
    {
      provide: AuthHttp,
      useFactory: authHttpServiceFactory,
      deps: [Http, RequestOptions],
    },
  ],

  bootstrap: [AppComponent]
})
export class AppModule { }

I have no Idea what to remove next. It seems 639KB is my minimum somehow?

Edit: Im talking about not compress files. The compressed would have a size of 144KB.

cliedelt avatar Feb 02 '17 10:02 cliedelt

@orgertot what is your main.js size running ng serve?

SquadraCorse avatar Feb 09 '17 18:02 SquadraCorse

are there any solution with new updates without --prod? It gives me 3.50MB vendor.bundle.js, it is still so big

noyancur avatar Oct 22 '17 09:10 noyancur

i agree this is a disaster ;(

reco avatar Oct 25 '17 15:10 reco

Why do you need a small bundle without --prod? The reason the dev bundle is large is mainly because of sourcemaps which can be disabled with --no-sourcemap. Then there's alot of minifying etc that doesn't get executed in a dev build aswell.

grizzm0 avatar Oct 27 '17 07:10 grizzm0

my vendor.bundle.js is 16.3 MB What i should Do ??

ghost avatar Nov 16 '17 11:11 ghost