Skip to content

Instantly share code, notes, and snippets.

@kaelig
Last active December 14, 2015 22:48
Show Gist options
  • Save kaelig/5160990 to your computer and use it in GitHub Desktop.
Save kaelig/5160990 to your computer and use it in GitHub Desktop.

Why Compass?

TL;DR: I definitevely don't have anything against Bourbon, and we can actually use it with Compass (Bourbon for most CSS3 and Compass for utilities, spriting, compilation & other functions). But not using Compass is missing a big advantage Sass has over LESS.

First, why NOT Compass

  • Doesn't work with libsass (yet — I read they plan on supporting libsass, probably later this year)
  • needs Ruby (for now), and installs the chunky_png gem
  • Slow compilation (because parsing image sizes, assembling sprites… actually takes time)

Cases where Compass would be useful for us:

  • CSS3 Mixins of course
  • when specifying a path to an image, Compass has a image-url() helper, looking for the image and if it doesn't exist, raises an error. Extremely useful when cleaning the image directory — no risk of deleting an image that is used by a component. Same for fonts with font-url().
  • spriting: Compass makes it dead simple: http://compass-style.org/help/tutorials/spriting/ — awesome for performance and maintainability
  • paths to images in production stylesheets: when compiling, Compass can distribute URLs to images with the asset_host configuration. For example, http://assets%d.ourcdn.com where %d can vary between 1 and 4. Handy to paralelize downloads — good for performance on desktop websites.
  • asset_cache_buster: if the image has changed, appends a timestamp ?1268738484 to images. Can even be tweaked to be image.1298698634.png instead of image.png?120798374.
  • Mobile dev: inline-image(path/to/image.png) Embeds the contents of an image directly inside your stylesheet, eliminating the need for another HTTP request. Same with font files.
  • the add_import_path config option enables us to add Sass files from multiple sources, very handy for a modular architecture

Nice to have:

  • image-height(path/to/image.png) and image-width(path/to/image.png): If dimensions of an image change, the CSS is updated automatically with the new dimensions. Not mandatory right now but it's good when exploring theming, and a must-have on an internationalized platform (images can change depending on the language — Compass deals with it seamlessly)
  • CSS3 mixins are far better than in Bourbon, especially for advanced gradients, transforms and animations.
  • compass stats: returns a table of statistics about the CSS codebase (Sass size & compiled size, number of selectors, properties…). Very handy to track the evolution of a codebase and make sure it doesn't get out of control through a particular badly written commit. Example: https://gist.github.com/kaelig/749082823cb32ccdf36d

Good things about it

@scottkellum
Copy link

Can’t forget the rich plugin ecosystem. Compass is way more than what you get out of the box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment