Skip to navigation

Disabling Rails sessions for JS and XML output

Published October 05, 2006

Every time your Rails app assigns a session to a visitor it creates a cookie with the session id and a relevant entry in the session store.

Whilst developing Web Connections I noticed sessions were being created for the JS and XML calls.

Apart from the performance overhead, you don’t really want to force cookies on users of the JS and XML output of your application.

So how do you disable sessions for the JS and XML requests? I just disabled sessions for all non-HTML requests:


class ApplicationController < ActionController::Base
  session :off, :if => lambda { |request|
    request.parameters[:format] &&
    request.parameters[:format] != 'html'
  }
end

Articles

toolmantim

I'm Tim Lucas, a user experience designer and developer currently in Sydney Australia.

I run a web application design and development company Agency Rainford, present on various technical topics, snap the occasional photo, tweet my going-ons, share teh codes and post other tid-bits to the tumble.

Most recently I published LAN hacking with Bananajour (June 11, 2009)

Shoot an email to and say hello.

Powered by complication and elaboration