Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialrajbee
6,657 PointsWhat are the other ways to optimize css ?
Other than Avoid @import and using Hosted Services, in which ways can we optimize our css ?
3 Answers
Kevin Korte
28,149 PointsIf you have multiple stylesheets, you can compile them into one bigger stylesheet. This makes fewer http requests, and so generally will load faster. You can also compress your css files, which strips out comments, line breaks, and any white space. This makes file size smaller, and fewer lines and characters to parse so it'll also help make the file load faster.
Both of these I do not recommend doing manually. There are great tools that can automate these tasks for you, like CSS pre-processors like Sass, Less, or Styles, and build tools like Grunt and Gulp.
Also to note, @import as sass file is perfectly fine. @import in a css file sucks. Because @import in a sass file runs at compile time, not load time, it won't affect page load speed. In fact, @import in a pre-processor like Sass is a great way to compile many smaller css files into one larger one.
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsIs it really necessary to learn "SASS" on the path of becoming a front-end-developer? What are the things I'll know after learning SASS?
Kevin Korte
28,149 PointsI'd say that depends on who you work for or with, and what you want to do. Sass is only one tool in the toolbox, there is also Less and Stylus that are basically the same thing, just with their own features and syntax.
Since I've written this, another now popular contender has come up, and continues to gain traction, and that's PostCSS
https://github.com/postcss/postcss#usage
I would say that, it makes sense for most front end developers, in most projects to use some sort pre or post processor. These tools typically introduce ideas into CSS that other languages already have, such as variables, loops, and functions, that are compiled down to vanilla CSS before it hits the browser.
Most of these libraries have a quick start guide, to give you a fly by 10-15 min intro into what they provide, and I would recommend taking an hour and checking out Sass, Less, Stylus, and PostCSS at a min to see if one of them makes sense for you.
Kevin Korte
28,149 PointsYeah, no problem