What follows in this series of articles are tips, gotchas and alternative explanations for what might not be clear in the official documentation.
Caching and the asset pipeline
As web developers we know that the browser cache can be trouble. When a fellow developer encounters an inexplicable visual glitch, our first reaction is “did you try clearing your browser cache?”
Safari on the Mac is particularly stubborn: sometimes “empty cache” (⌥⌘E) is not enough, and you’ll need to quit and relaunch as well. If you are wrestling with favicons, a more drastic measure is needed: choose Safari→Reset Safari to clear that particular cache. And of course you’ll want to restart Safari again for good measure.
The good news is that with the introduction of the asset pipeline, Rails has taken big strides to address browser caching problems. If you’ve glanced at the asset pipeline guide you probably know that Rails sends
must-revalidate headers in development and uses cache busters in production. Browser caching solved, right?
The bad news is that in development, Rails adds a new asset cache to the mix. This cache speeds development–without it your app would be nearly unusable–but as a result, mysterious glitches can pop up that are only solved by clearing the cache. As with the browser, it is a helpful to know how to clear this cache too.
To wipe out the asset pipeline cache, a brute force
Finally, if you are experimenting with
rake assets:precompile in your development environment (more on this in a later article), you’ll also want to
rm -rf public/assets/* afterwards to clean that up.
The Compass project is undergoing major changes at it approaches its 0.12 release. As a result, the recommendations for integrating Compass with Rails are in flux. The latest and greatest technique involves the new compass-rails gem.
If you plan on using Compass with the Rails asset pipeline, make sure you read our article on the subject, which covers:
- installing the appropriate gems
- organizing scss assets
- configuring Compass
- tweaks needed for production
Continue reading part 2 of this series: Production.comments powered by Disqus