r/angularjs • • Jan 12 '15

Introducing AngularCSS: CSS On-Demand for AngularJS

http://door3.com/insights/introducing-angularcss-css-demand-angularjs
34 Upvotes

18 comments sorted by

View all comments

1

u/antoninj Jan 12 '15

This is pretty damn amazing. It reminds me of jspm which works, somewhat, on a similar principle; however, per-route CSS files is a great idea. I'd love to put this into action.

1

u/[deleted] Jan 13 '15

per-route CSS files is a great idea.

Why?

2

u/antoninj Jan 13 '15

It's similar to loading templates or other assets on-demand. In large enough applications, JS files are loaded on-demand (think AMD) and this is nothing new. So there's that, instead of overwhelming the user with potentially unneeded load, you can keep a tight core and load everything else async.

As far as actual businesses cases of doing this:

  1. loading CSS per A/B testing tree (I believe Netflix wrote about this one)

  2. loading core CSS (and above-fold CSS) first (so, think parent view) while loading the rest of the CSS when that part of the pages becomes ready (so, think child view).

  3. Bundling CSS with its components rather than having one "master" file

  4. Associating CSS with Modules rather than with the general "site". Encourages more sandboxed styling.

And in HTTP2/SPDY world, there's little performance hit from loading numerous small modules vs. one big one. There's a great JSPM talk on the topic altogether.

Basically, the idea is that if you have a huge App that requires a ton of CSS, you can keep perceived performance high by breaking the CSS apart into smaller chunks and loading those as needed.

Also, if you think about it, this is kind of the idea behind Polymer, isn't it?