The key to successful refactoring is to establish up front basic principles for the refactor. While these will differ from team to team and project to project, there are some principles that are more or less universal.
- [Instructor] CSS Refactoring is not…a one-size-fits-all practice.…Every developer and every team have their own…preferences and best practices they use to…improve and simplify their own code.…That said, there's some general principles…that most developers can agree with.…First, avoid specificity.…Use general CSS rule selectors over specific ones…to ensure reuse and avoid writing individual rules…for each little piece of displayed content.…This is also a performance issue.…
Browsers read your selectors from right to left,…meaning the quicker you can narrow down…the element you are looking for the better,…i.e. body main section .cta-box .cta-button a…will read as give me every anchor that is also…in this .cta-button container that is also…in the .cta-box container that is also in the section…that is in the main that is in a body, etc.…Whereas .cta-button a will produce the exact same result,…just with a lot less queries.…
Number two, use the cascade.…The browser reads the style sheet from top to bottom,…giving more weight to rules and properties…
Released
9/10/2018- CSS optimization
- Refactoring many stylesheets
- Structuring CSS
- Reordering properties automatically
- Fixing errors
- Ignoring warnings
- Auditing stylesheets with Chrome
- Quarantining unused code
- Modularizing CSS
- Using task runners
- Optimizing CSS for delivery
Share this video
Embed this video
Video: General refactoring principles