Hey there - I’ve got a problem I’ve been trying to find a solution
to. I’ve got a page which contains a list of prices which are
gathered from various websites - however it takes a while for the
prices to be collected, so the page takes a while to load ( up to 30
seconds ). I’m looking for a technique for the page to load the
elements as they become available.
I tried this, but the result isn’t passed to the browser until it’s
complete:
render :update do |page|
## Set all the prices to spinners.
for shop in Shop.find(:all) do
page.replace_html( "shop_#{shop.id}", "<span
class=‘label’>#{shop.name}")
price = shop.get_pricing(@item)
page.replace_html( “shop_#{shop.id}”, :partial =>
“price”, :object => price ) unless price.nil?
end
end
I’ve been thinking of setting a status of the price to “loading”,
then having an observer on the page to check every few seconds, but I
don’t much like the idea of a page asking the server for an update
every few seconds once the page is complete. So, is it possible to
alter the observer to stop observing once the elements are all loaded?
Or is there some much more elegant way to achieve this?
Or is there some much more elegant way to achieve this?
…if you load some url in an iframe, it doesn’t stop the initial
parent-page from loading (ie, it won’t take 30 seconds to load), and
stops asking for requests once the iframe is loaded.
i found it works great on my app…maybe worth checking out in your case
I’ve been thinking of setting a status of the price to “loading”,
then having an observer on the page to check every few seconds, but I
don’t much like the idea of a page asking the server for an update
every few seconds once the page is complete. So, is it possible to
alter the observer to stop observing once the elements are all loaded?
Use a Javascript Event observer on window load (or document ready if
you use lowpro) to trigger the loading of each individual shop price.
I’m guessing requesting the price of an individual shop doesn’t take
30 seconds. It would involve some handwritten javascript, but it will
surely pay off in the end.