Comments (11)
We also seen this in Angular SSR angular/universal#2106
from critters.
@developit , @alan-agius4 , @danielroe
I successfully made a fork of Critters and implemented dropcss to prune not used CSS rules (keeping keyframes and fonts Critters features).
To parse and process stylesheets (preload strategy, merge stylesheets, etc) i'm using node-html-parser. I found it faster than parse5 to parse and serialize html. This is just a little gain of speed.
The overall result is a huge speed improvement mainly thanks to dropcss
. I didn't do proper benchmarks but i would say this is around 10x faster.
The only drawback is that html and css parsers from dropcss
are very sensible. Only valid html and css inputs could be processed.
I didn't push my locals commits to the forked repository yet. I will do it later and let you know if some of you are interested.
It also opens the possibility to prune external stylesheets from multiple Critters runs with the same (or not) instance.
This is possible thanks to the whitelist technique from dropcss.
from critters.
@brjadams we didn't move on with it, and just turned off inline critical CSS in the meantime
from critters.
I've made some changes in v0.0.19 to help with improving the speed of processing. It's a combination of adding a cache and also some user intervention. Please try this version out and let me know if it helps
from critters.
IIRC @janicklas-ralph has done some experimenting to improve performance for this use-case. It's a trade-off though, and any caching would need to be controllable by the caller.
from critters.
@freddy38510 any news on that? do you have your changes available anywhere? i'd love to try it on our project and see if it solves the performance issues
from critters.
I ended up creating a new project called beastcss because the code was very different from Critters.
You can make a try and open new issues if you find some bugs or for asking new features. And please, i'll be glad if you let me know about the performance improvement :)
from critters.
I'm seeing 4x-5x faster processing on our typical html page after switching to dropcss-based approach.
It's definitely a great boost - but still not sufficient for enabling it in production for us (with Angular Universal).
EDIT: actually, 10x using beastcss
with caching of parsed stylesheets
from critters.
I came to this solution under a different context than yours. I'm using a Static Site Generator for Quasar with SSR pre-rendering. Also, i didn't test beastcss with html that contains a lot of DOM nodes.
Did you measure the duration of the overall processing ? What would be the maximum acceptable duration for your use-case ?
from critters.
Great question. So when we tried to enable inlineCritical on prod with Angular last time, we got around 500-600ms overhead of pure computations, and it was just too much, we started dropping requests.
Frankly I'm not sure how much lower it needs to be for our case - will have to try and see, I guess.
10x improvement (with beastcss) sounds like it should do the trick.
from critters.
@amakhrov did beastcss do the trick? How did you go about implementing this in Angular with SSR?
from critters.
Related Issues (20)
- Branching webpack versions
- `pruneSource: true` not pruning files
- Non-critical rules are erased from inline styles HOT 6
- Local font source is not recognized as valid
- relative urls within css
- Allow attributes to be set on generated style tag for CSP
- How to use critters in next.js v13 HOT 2
- critters de-encodes html entities HOT 1
- Parse include/exclude markers with @preserve or /*! hints
- Cannot read properties of undefined (reading 'setAttribute') HOT 6
- Disable font-face exclusion
- The `allowRules` option is missing in the types and documentation
- Passing includeSelectors config HOT 2
- Add the option of a prefix path
- Used css attribute selector gets removed by critters
- Feature Request: Expose method `processCss` which returns inlined css only
- Simple Example fails
- Building Angular 17.1 with Angular CLI when using Bootstrap 5.3.2 results in Critical CSS Inlining failing because 2 rules are skipped due to selector errors HOT 9
- 2 different lock files
- The css modules key styles are not inlined when configuring generateScopedName. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from critters.