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/ -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Witold Rugowski
2006-Sep-20 14:33 UTC
Re: Generate JS from RoR - strange delay with send_data
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/ -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Jeremy Wells
2006-Sep-20 15:40 UTC
Re: Generate JS from RoR - strange delay with send_data
Witold Rugowski wrote:> 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. >i don''t know if it would help, but you could send a content-length header --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---