Announcing Rack::ChromeFrame
Google Chrome Frame is a great way to enable modern browser features without forcing the user to upgrade or switch web browser. Once installed it is activated by either including a meta tag in the head of each page or by setting a header with the same name and value in responses from the web server. Specifically:
X-UA-Compatible: chrome=1
The inclusion of the meta tag or setting the header is a good candidate for Rack middleware as it doesn’t need to interact with the application at all. A quick search revealed some existing work by Luigi Montanez of sunlightlabs. This implementation injects the meta tag into html responses. Favouring setting the header I created a very simple rack middleware and bundled it up as Gem. For building and releasing the gem I used Jeweler, which made the process totally painless:
% jeweler rack-chromeframe
Edit code…
% rake build
% gem push pkg/rack-chromeframe-1.0.0.gem
The gem is called rack-chromeframe and the code is on GitHub.
Using the Gem
Install
gem install rack-chromeframe
Rails
To use Rack::ChromeFrame in a Rails project:
Add the following gem dependency you your config/environment.rb:
config.gem 'rack-chromeframe', :lib => 'rack/chrome_frame'
Then use the middleware (also in config/environment.rb):
config.middleware.use "Rack::ChromeFrame"
Rack
To use Rack::ChromeFrame in a Rack application (such as Sinatra) add the following to your app:
gem 'rack-chromeframe'
require 'rack/chromeframe'
use Rack::ChromeFrame,
run app
That’s it! Now all your responses will have the X-UA-Compatible header set to enable Chrome Frame.
