Posted by Vince Wadhwani on Oct 11, 2006

I was having this really strange issue where an RJS page was working on my local machine booting webrick but not on my Ubuntu server running Lighttpd. I booted webrick on my server and confirmed everything worked so the problem *had* to be with lighttpd. I upgraded from Dapper's standard 1.4.11 to the fresh 1.4.13 but it still didn't help.

Luckily, I got some help on the forums and from firebug. If you run into an issue like the one described above, I hope this helps you:

Using the firebug console, I was able to see the headers when I clicked through on my page. Here is a comparison:

WORKED (webrick)
Cache-Control: no-cache
Connection: close
Date: Tue, 10 Oct 2006 19:56:41 GMT
Content-Type: text/javascript; charset=UTF-8
Server: WEBrick/1.3.1 (Ruby/1.8.4/2005-12-24)
Content-Length: 2014
Set-Cookie: _session_id=5d3950e52b565ec95c26509d573f913f; path=/

DID NOT WORK (lighttpd)
Connection: close
Transfer-Encoding: chunked
38.909643Content-Type: text/javascript
Set-Cookie: _session_id=246ae40922c0fd45f1514aeb4bf790ae; path=/
Cache-Control: no-cache
Date: Tue, 10 Oct 2006 19:41:35 GMT
Server: lighttpd

See that 38.909643? Because it was sitting in front of the Content-Type: text/javascript the browser was not correctly interpreting the code as javascript. The 38.909643 was there because of a print statement in my code. Print, like warn, is a method of debugging ruby code. It can be used if you want to confirm a variable is correct for instance.

Anyway, because I had forgotten to take out that print statement lighttpd was incorrectly passing the Content-Type. I'm pretty sure this is a bug with lighttpd but I did not test it in Apache2. Still, I hope it saves others out there some grief.