I'm developing a mobile website and am using an iPhone for testing it. One of the .jpgs used was faulty and displayed as a black rectangle in the iPhone's Safari browser. The code was then changed and there is now a .png image instead. For some reason even after clearing Safaris cache that image is still black, and I need a new phone that has never visited the website before in order to display it correctly.

Why is that happening and how can I fix it?

2 Answers 2


Sounds like an iPhone bug/feature where it will cache some images (and not clear them properly).

The fix seems to be to put a random number in a query string after the images on your site.

eg picture1.png?2011242424

Some web frameworks will do this automatically (eg rails). Otherwise you could do this on just the affected image and see if it fixes it.


You can try browsing to the image itself, refreshing that page - that usually clears the cache for the image.

However best practice in web development is to follow @RobZolkos 's advice about putting a number string after the image src. When you change the image, you change the number, which forces it to load again. A little off topic, but check out HTML5 Boilerplate's cachebusting which does this for you automatically in the build script.

  • The problem is Safari doesn't even notice that the string changed. The src is still ending in *.jpg even though the server delivers it as *.png
    – Lars
    Apr 18, 2011 at 12:33
  • @Lars Have you checked that it works on a desktop browser? And are you definitely going to exactly the same URL? If you know it's working on the desktop, email the URL to your iPhone and click on the link. Just checking the obvious, because it sounds like a server problem rather than an iPhone one.
    – Dan Blows
    Apr 18, 2011 at 12:43
  • Yes I did check it in Firefox with User Agent Switcher and it works fine there. The URL is definitely the same. But maybe it could be the Drupal that is used for that site?
    – Lars
    Apr 18, 2011 at 12:48
  • Ah yes... didn't think of that. Clear Drupal's cache. It could be that you are not logged in on Drupal, so it is showing you a cached version of the page. Go to admin/settings/performance - clear cache is at the bottom.
    – Dan Blows
    Apr 18, 2011 at 12:55
  • Hm, clearing the cache didn't help. Also it seems that a changed URL won't even get recognized, since it is still using the wrong file extension.
    – Lars
    May 2, 2011 at 9:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .