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
<script> 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<< GENERATE_JS_CODE_FROM_POINTS
}
send_data(output_data, :content => "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 Rugowski
http://nhw.pl/
on 12.09.2006 19:49
on 20.09.2006 16:33
Witold Rugowski 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/ Best regards, -- Witold Rugowski http://nhw.pl/
on 20.09.2006 17:49
Witold Rugowski wrote:
>
i don't know if it would help, but you could send a content-length
header