2

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?

Chris
  • 2,888
  • 4
  • 34
  • 50
  • 3
    You could put in a PHP URL in `src` attribute and use `sleep()` in PHP? Or if you don't want to change source, you could use URL rewriting to write the image request to a PHP page. – Ejaz Apr 28 '13 at 12:08
  • Google image search restricted to "bigger than 4MP", then use one that loads slowly for your test case? Caching may be an issue, though.... – Stefan Haustein Apr 28 '13 at 12:14
  • Look at http://stackoverflow.com/questions/6929662/how-do-i-abort-image-img-load-requests-without-using-window-stop – kirugan Apr 28 '13 at 12:15
  • @Ejay: That's the route I'd go down... add it as an answer and I'll +1 it ;). – Matt Apr 28 '13 at 12:17

2 Answers2

2

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

Community
  • 1
  • 1
Ejaz
  • 8,229
  • 3
  • 31
  • 48
  • Thanks, that's the way I went. Isn't an public URL, but in my case PHP was good enough. I made it even a bit more comfortable by setting the delay by a parameter: `` – Chris Apr 28 '13 at 12:56
0

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.

rai.skumar
  • 9,001
  • 5
  • 37
  • 54
  • I don't want to pre load images. Actually I'd love to but cant as this image source if from user content... – Chris Apr 28 '13 at 12:54