Flickr call slowing page render/build in PHP - ideas?

I’m developing something at the moment which uses a Flickr API call to dynamically generate some inline images related to the content. There is a noticeable delay in getting this info, though.

While I’m waiting for the images to come from Flickr and for the HTML to be generated and written, I’d like the page content up to that point to be rendered … then have that pause … and then continue.

I’ve tried placing the PHP that gets the Flickr stuff right at the end of the page, with the thought that I can use jQuery to them move it back up in to the appropriate place on the page - my thinking - get it last, so I can put the rest of the page up first.

I wondered if flush() was the answer and tried experimenting, but having tried a number of variations on that, none of it works. In all cases I get a completely blank page (just the <title> in the browser showing), no source code if I do a View Source until the Flickr stuff is done … and then BANG! All loaded in one go. Not good.

So, I’d appreciate some thoughts. Have I misunderstood the flush() method, perhaps?

I have HTML with include statements through the page. Mixture of HTML and embedded <? echo ?> statements. I think this is the reason why flush() isn’t working, right?

I’m no PHP expert - I know enough to get by :wink: - so if you have an idea or two, please bear this in mind.

One thought I had:

  • move all PHP logic to separate file
  • load the page, nice ‘n’ quick
  • load the PHP Flickr file after using AJAX (via jQuery).

This should stop the blank page issue. But is it the best way?

Thanks for your advice.

If it’s the API calls that is causing the delay, it’s not really going to matter when you make them.

You could implement some caching though, that is, if any of the queries are likely to return the same data. :slight_smile:

Can you pop up some code reproducing this delay?

Crikey. That’s a definite no. I’d sooner gouge my eyes out with rusty spoons than use tables :wink:

No tables at all, but the page does nothing until it’s got what it needs from Flickr via PHP.

Are you displaying you page content inside html tables?

I’d go the AJAX approach. Put a loading spinner there and fetch the images once the page loads

Flickr returns the image urls stunningly fast, the images turn up from the farms a bit slower of course.

I’d guess its your jquery that is slowing it all down and making you wait.

Did you try a straight, PHP echo to HTML of the urls?

I’ve had a page with 125+ thumbnails load almost instantly, then the images turn up chequerboard fashion.

Try straight PHP/HTML and see if that works first.