Reputation: 359
In Angular 2 we have several choices to make styles for our application. I'm trying to deduce if it is better to make a one big minified .css
file, using some task runner (ex. Gulp) or to use Angular 2 styleUrls: ['myfile.css']
for every component. In which way, the performance in a browser will be better ? Let's say we have about 100 components, so we have to load 100 css files to our browser, or one, bigger, minified css file in the section for example.
What do you think ?
Upvotes: 3
Views: 1917
Reputation: 2138
I would personally feel the doing separated files would work like a charm.
PROS:
CONS:
For HUGE one file.
PROS:
CONS:
Everyone has their own perspective. You would like to read this article.
Upvotes: 4
Reputation: 1403
Step1
Yo need to determine how much the whole CSS file weights, after minified and G-zip Compressed... If is just a few kbs you should consider concatenating all your styles into one single file... remember you can always cache that file into the client's machine so it doesn't need to download the file every time the user loads the page...
Step2
If worth it... you should Isolate CSS rules for specific components... rules that you are not going to reuse in any other component.
Once you do this you will have two options:
If your component needs too many CSS rules... I would say more than 50 lines, it will become hard to maintain, since you wouldn't get IntelliSense from your IDE or any auto-indentation feature... so you may consider using: styleUrls: ['myfile.css']
and have these properties in its own file, easier to maintain and if you are using a CSS preprocessor to generate your CSS files... this will be a better approach.
Note that every time you load this component for the first time in your SPA your app will Request that CSS file from your server
HTTP-REQUEST
.
However, if your component only requires a few lines for styling you may want to use
styles: ['h1{color:red}']
inline... this would load faster, since it prevent the app to make another HTTP request to your server to get the styles
Upvotes: 0
Reputation: 514
I personally (for my project at work) used a large minified file rather than lots of smaller ones, I did try both , over different components of the app and discovered that one minified , central file did the trick for me.
Upvotes: 1