Reputation: 685
There were many questions on this topic: Angular 2 Initial loading progress Show progress bar when Angular loads its files? and etc
But they are old and unanswered. So we still have the question. I know its complicated a bit, but I believe this is not impossible. We have really big bundles in dev env, like 10mb+, and many guys who visit our app via VPN suffer from white page disaster - files are being loaded slow, they have to wait for a while, and if one them fails then the page stays blank
Is there a way to track real progress of angular application initial loading process? Can we show our user a real percentage of initial loading process?
Upvotes: 1
Views: 52
Reputation: 685
I found the answer following a hint from other question - https://stackoverflow.com/a/78437730/2779773
The main idea is to track resources loading process using PerformanceObserver. There are some complications:
Later I'll post the final code
Upvotes: 0
Reputation: 47
In index.html file Add your loader content under <app-root>
tag.
HTML :
<app-root>
<div class="pageLoaderMain">
<div class="pageLoaderContent">
<div class="loaderImage">
<img src="assets/loaderimage.gif">
</div>
<div class="loaderContent">Loading...</div>
</div>
</div>
</app-root>
CSS :
.pageLoaderMain {width:100%; height:100%; z-index:99990; left:0;top:0%;color:#cdcdcd; font-size:0.8em; text-align:center; position:fixed; background:rgba(0,0,0,0.5);}
.pageLoaderMain .pageLoaderContent{background: none;z-index:99991; left:46%; top:50%; position:absolute; overflow:hidden; padding:5px; border-radius: 23px; -moz-border-radius: 23px; -webkit-border-radius: 23px; border: 0px solid #000000;}
.pageLoaderMain .loaderImage{float: none; display: block;text-align: center;}
.pageLoaderMain .loaderContent{float:left;margin:8px 2px 8px 5px; color:#fff; font-weight:300; font-size:13px;}
For Showing % with loader you can take reference from : https://medium.com/@bananicabananica/its-so-easy-with-angular-part-3-page-loader-8d4201e0f266
Upvotes: 0