# Generate JS from RoR - strange delay with send\_data

**URL:** <https://www.ruby-forum.com/t/generate-js-from-ror-strange-delay-with-send-data/68441>\
**Category:** Rails\
**Created:** [September 12, 2006, 7:49pm UTC](https://www.ruby-forum.com/t/generate-js-from-ror-strange-delay-with-send-data/68441 "2006-09-12T19:49:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![viciu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7ba0ec/32.png) [@viciu](https://www.ruby-forum.com/u/viciu)\
**Post date:** [September 12, 2006, 7:49pm UTC](https://www.ruby-forum.com/t/generate-js-from-ror-strange-delay-with-send-data/68441/1 "2006-09-12T19:49:38Z")

</div>

Hi!

I need to generate some JS from Ruby. This is no AJAX related stuff so  
RJS templates are not help to me. Also I want to not mix JS with HTML,  
so putting JS in .rhtml templates is no go for me.

Currently I made some action in controller, prepared JS code and I’m  
sending it via send\_data as ‘text/javascript’. In .rhtml templates I use

 tag with src pointing to right controller/action. All works as I wanted but there is one issue - after sending data there is big delay before JS generated this way is downloaded. I have sniffed traffic with Ethereal, and whole JS code is send very fast only closing connection looks like: t=0, server -\> client last packet of data t=t+ 20 ms, client -\> server ACK t=t+ 29 seconds server, -\> client FIN, ACK ..... normal TCP teardown follows 29 seconds ! Am I doing something wrong? My action looks like (I've removed real JS since it is not problem with generation of JS only with sending): def show\_route Point.find(:all, :conditions =\> ["route\_id = ?", pid]).each {|x| output\_data\< "text/javascript") end I'm using Rails 1.1.6. Or maybe there is some other way to generate 'custom' JS not in .rhtml? Best regards, Witold R. http://nhw.pl/

---

<div class="post-metadata">

**Author:** ![viciu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7ba0ec/32.png) [@viciu](https://www.ruby-forum.com/u/viciu)\
**Post date:** [September 20, 2006, 4:33pm UTC](https://www.ruby-forum.com/t/generate-js-from-ror-strange-delay-with-send-data/68441/2 "2006-09-20T16:33:06Z")

</div>

Witold R. wrote:

> 29 seconds ! Am I doing something wrong? My action looks like (I’ve  
> removed real JS since it is not problem with generation of JS only with  
> sending):

This is related somehow to WEBrick (which I was using as HTTP server)  
and squid proxy. For some reason there is something wrong with closing  
connection - connection closes only after timeout in WEBrick. I switched  
to lighttpd and all is working ok.

But as a side effect I have patch to Ruby interpreter which dumps all  
called methods with timestamps (during code execution) - this way I  
discovered place where delay was generated. Maybe someone find this  
useful - more details on

[http://nhw.pl/wp/2006/09/20/how-to-start-debug-ruby-programs/](http://nhw.pl/wp/2006/09/20/how-to-start-debug-ruby-programs/)

## Best regards,

Witold R.  
[http://nhw.pl/](http://nhw.pl/)

---

<div class="post-metadata">

**Author:** ![viciu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7ba0ec/32.png) [@viciu](https://www.ruby-forum.com/u/viciu)\
**Post date:** [September 20, 2006, 5:49pm UTC](https://www.ruby-forum.com/t/generate-js-from-ror-strange-delay-with-send-data/68441/3 "2006-09-20T17:49:06Z")

</div>

Witold R. wrote:

> 

i don’t know if it would help, but you could send a content-length  
header
