Caching with Rails

When working with rails, it’s quite useful to change a source file, save it, and reload a web application merely by refreshing the web browser. This had been working great, until one day when my changes didn’t appear in the browser.

I tried clearing the cache on the browser, but it didn’t help. Only when I restarted rails would the change get picked up. Considering that this took a good bit longer than simply refreshing the browser, this caused a serious drain on my productivity and warranted an investigation.

After some initial searching, I discovered the config.cache_classes setting. Here is how the documentation describes it:

config.cache_classes controls whether or not application classes and modules should be reloaded on each request. Defaults to false in development mode, and true in test and production modes. Can also be enabled with threadsafe!.

That sounded promising - all I had to do was disable caching. I went back to development.rb, and here is what I saw:

config.cache_classes = false

Caching was already disabled. But Rails still seems to be caching. What’s going on? After reading a blog post by Aaron Patterson, things made a little more sense.

Read More

Uglified Unicode on Rails

TL;DR - IE doesn’t like minified unicode. To fix this, create a custom passthrough minifier to disable minification of unicode when using uglify in the rails asset pipeline.

I’m pretty new to rails, so please let me know if I’m off the mark here.

Asset Pipeline

Rails has an interesting component called the asset pipeline that, among other things, can combine all of your js files into one file, and all of your CSS files into another, then it can strip out whitespace and rewrite your code to make it smaller, by doing things such as replacing long variable names with short ones. This is called combining and minifying. Combining and minifying are important because they can help a web page to load faster. A web page can load noticably faster if it has a single 150kb file to load from the server rather than 25 files that are 10kb each.

Without question, we wanted to minify and combine our code using the asset pipeline. For more information on setting up minification, see the asset pipeline documentation.

IE and Unicode Problems

However, we had strange results with the minification. When our code was _not _minified, it worked great in both IE and Chrome. After being minified by the asset pipeline, however, it worked great in Chrome but some parts of our app mysteriously failed in IE.

Read More