ClickAider
You are currently browsing the Bogle’s Blog weblog archives for the day Thursday, February 21st, 2008.

Enabling browser caching of static content in Mongrel

This post describes a simple snippet you can include in your rails environment to enable caching of static content served up from Rails via Mongrel in a development environment.

By design, Mongrel doesn't include configuration options for caching headers on static content.  Mongrel is optimized for dynamic content, and in a production deployments another web server such as Apache is used to render static content.

However, in a development environment, the lack of static content caching can be an issue for pages with large numbers of images, scripts, and stylesheets. Waiting to fetch all of these resources on every page request makes iterative development feel sluggish and doesn't accurately reflect what will occur in production.

The class used in Mongrel to serve static content is called DirHandler.  By adding the following lines to your environment.rb file, you can extend DirHandler to set the Expires and Cache-Control headers so that all static content lives 10 years.  As long as you refer to that content using the Rails helpers like "image_tag", timestamps will be appending to the URLs so that new versions of these assets will be correctly loaded whenever you update the files.

RUBY:
  1. if defined? Mongrel::DirHandler
  2.   module Mongrel
  3.     class DirHandler
  4.       def send_file_with_expires(req_path, request, response, header_only=false)
  5.         response.header['Cache-Control'] = 'max-age=315360000'
  6.         response.header['Expires'] = (Time.now + 10.years).rfc2822
  7.         send_file_without_expires(req_path, request, response, header_only)
  8.       end
  9.       alias_method :send_file_without_expires, :send_file
  10.       alias_method :send_file, :send_file_with_expires
  11.     end
  12.   end
  13. end

New Mergelab Update

Mark has written an excellent summary of our new Mergelab release. I've posted a few highlights below, see the full post for all the details.

Automatic Summaries of news and information about your people:image

Inline, expandable post previews image Search and keyword filteringimage

Improved news customization: We've added the ability to hide news about someone (using the "Ignore updates" link on their contact card) and to hide all twitters (using the checkbox in account settings).

Variety launches The Biz, powered by Jobster

Congrats to my former coworkers over at Jobster for shipping thebiz.variety.com, a career network for the entertainment industry on behalf of Variety.