Chris
Chris

Reputation: 3405

Image that doesn't finish loading over HTTP on purpose

I'm creating a web application that uses heavy JavaScript. And there I must handle the case when a image created by

var myImg = new Image();
myImg.src = 'http://...../';

doesn't load soon enough. So adding a handler like

myImg.onload = handlerFunction;

is easy.

But how can I debug that?
I.e. how can I make a image load slowly (or even never...) on purpose?

Is there probably a web service that's offering me such an image that I can easily include by using only the URL to that picture?

Upvotes: 2

Views: 83

Answers (2)

Ejaz
Ejaz

Reputation: 8872

Here goes as OP finds it useful in his scenario :)

You could put in a PHP URL in src attribute and use sleep() in PHP.

HTML

<img src="/my_image_test.php" alt="testing behavior on image load delay" />

my_image_test.php

sleep(10); //delay for 10 seconds
header('Content-Type: image/jpeg');
//output image here if you have to

Or if you don't want to change source, you could use URL rewriting to rewrite the image request to the PHP page

Upvotes: 2

rai.skumar
rai.skumar

Reputation: 10667

If you want to pre-load images you can use CSS/JavaScript.

Is there probably a web service that's offering me such an image that I can easily include by using only the URL to that picture?

Depends, what kind of images you are looking for. You can search image section of google.com. If you can find it you can use its URL in your application.

Upvotes: 0

Related Questions