0

I have a small project that has packages (angular cdk, angular material, and firebase). Yet I have a built vendor.js file with size 4 MB.

As an approach to deal with problem, I want to show the progress of loading on slow connections (it takes up to 2 minutes to load 4 MB), so that users can see app is loading.

I have installed PWA and service-worker so that the app does not reload each time.

FindOutIslamNow
  • 1,169
  • 1
  • 14
  • 33
  • 1
    Are you using angular cli? If yes, are you running `ng build --prod`? I'm very surprised by the 4 MB file if you're using --prod... – maxime1992 May 13 '18 at 09:26
  • I am using cli. Notice that `--prod` is no longer an argument in 6, it is now an option in `angular.json` file – FindOutIslamNow May 13 '18 at 12:20

2 Answers2

0

In order to answer the question: There is no easy way to show the user how long he has to wait till the app is loaded, but you can show him a simple animation.

Just include some CSS animations in your index.html. Everything inside app-root will be replaced by the app after startup.

<!-- index.html -->
  <!doctype html>
  <html>
    <head>
      <style>
        .spinner {
          height: 200px;
          width: 200px;
          animation: rotate 2s linear infinite;
          transform-origin: center center;
          position: absolute;
          top: 0;
          bottom: 0;
          left: 0;
          right: 0;
          margin: auto;
        }
        @keyframes rotate {
          100% {
            transform: rotate(360deg);
          }
        }
      </style>
    </head>
    <body>
      <app-root> <!-- selector from app.component.ts -->
        <!-- loading layout replaced by app after startupp -->
        <svg class="spinner" viewBox="25 25 50 50">
          <style type="text/css">
            circle{stroke:url(#MyGradient)}
          </style>
          <defs>
            <linearGradient id="MyGradient">
              <stop offset="5%" stop-color="#F60" />
              <stop offset="95%" stop-color="#FF6" />
            </linearGradient>
          </defs>
          <circle class="path" cx="50" cy="50" r="20" fill="none" stroke- 
          width="2" stroke-miterlimit="10"/>
        </svg>
      </app-root>
    </body>
  </html>

Based on this Tutorial.

Apart from that, as maxime1992 said, you should use Angular in Production mode for minimum file sizes.

Daniel Habenicht
  • 2,133
  • 1
  • 15
  • 36
  • Thanks. I have already implemented the animation for loading. I just want to show the actual progress of loading (e.g. 54%) with a progress bar. – FindOutIslamNow May 14 '18 at 10:38
-1

Try calculating the download % in by loading the JS file in an AJAX request like here and show that number in your progress bar.

Anand
  • 9,672
  • 4
  • 55
  • 75