# How to load many slow items into a page?

**URL:** <https://www.ruby-forum.com/t/how-to-load-many-slow-items-into-a-page/109462>\
**Category:** Rails\
**Created:** [July 15, 2007, 9:24am UTC](https://www.ruby-forum.com/t/how-to-load-many-slow-items-into-a-page/109462 "2007-07-15T09:24:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e5b9ba/32.png) [@dkam](https://www.ruby-forum.com/u/dkam)\
**Post date:** [July 15, 2007, 9:24am UTC](https://www.ruby-forum.com/t/how-to-load-many-slow-items-into-a-page/109462/1 "2007-07-15T09:24:10Z")

</div>

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?

Cheers,  
Dan

---

<div class="post-metadata">

**Author:** ![dkam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e5b9ba/32.png) [@dkam](https://www.ruby-forum.com/u/dkam)\
**Post date:** [July 15, 2007, 9:40am UTC](https://www.ruby-forum.com/t/how-to-load-many-slow-items-into-a-page/109462/2 "2007-07-15T09:40:23Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![dkam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e5b9ba/32.png) [@dkam](https://www.ruby-forum.com/u/dkam)\
**Post date:** [July 15, 2007, 11:17am UTC](https://www.ruby-forum.com/t/how-to-load-many-slow-items-into-a-page/109462/3 "2007-07-15T11:17:22Z")

</div>

On 15 Jul 2007, at 09:23, Dan M. wrote:

> 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.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![dkam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e5b9ba/32.png) [@dkam](https://www.ruby-forum.com/u/dkam)\
**Post date:** [July 16, 2007, 3:01pm UTC](https://www.ruby-forum.com/t/how-to-load-many-slow-items-into-a-page/109462/4 "2007-07-16T15:01:18Z")

</div>

Thanks for that - I’ll give those methods a shot.

Cheers,  
Dan

On 15/07/2007, at 19:21 , Peter De Berdt wrote:

> Use a Javascript Event observer on window load (or document ready
> 
> >

–  
Dan M.
