473,241 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

IE caches wrong image sizes

Hi there,

I have a strange problem in Internet Explorer (IE6 and IE7). I'm writing a JavaScript application which allows the user to edit a photo composition. So when the user selects a photo then a frame is drawn around it with resize and rotate buttons. Now it happened to me that I replaced these buttons (32x32) with larger images (48x48). The filenames were not changed, I only copied the new images over the old ones. Then I reloaded the page and the new buttons were displayed but their positions were not calculated correctly. After some research I found out that Internet Explorer still thinks the new buttons are 32x32 pixels even if it correctly displays the NEW buttons.

I cleared the caches, I restarted the browser, I even restarted Windows but IE still remembers that the buttons are 32x32. The only solution I found so far is renaming my buttons so IE reads the new image sizes...

I made a simple demo for this problem to show you. First of all I made a PHP script which generates and returns a randomly sized image. Be assured that this PHP script is not the problem and even some cache-relevant headers which may be send by PHP are not the problem. The PHP script is only there to simplify the demo. You can use a static image instead if you like and resize it manually before each request.


This simple page just loads an image (test.php, which generates randomly sized image) with JavaScript, waits until it is loaded and then prints the image size. Try it in Firefox and you'll get different image sizes on each request. Try it in IE and you always get the first image size. I have not done this in this demo but in my real application I could see that the NEW image is definitely loaded. Only the image size is wrong. So it's not a standard image cache problem where IE does not reload the image. The image IS reloaded but the image size is always used from the first loaded image with the same URL. I did not found a way to tell IE to "forget" this image size. If you know one, please help!

Also interesting is the fact that it works if the image is also loaded via HTML. The image size is only cached if the image is ONLY loaded via JavaScript. See this example where I also include the image with a standard HTML image tag. Suddenly the JavaScript code works:


All this sounds very strange and is annoying as hell. Sure, I could add a random query string to the URL of the button images but then all browsers would no longer cache the button images at all. Up to now I only see the solution to preload the button images with standard HTML code (Using hidden img tags on the page). If you know a better solution then please help.
Sep 10 '07 #1
3 3886
I had something similar to this awhile back. To trick IE into thinking it hasn't cached the image, I appended a random GET variable to the end of the url. For example, if the image's name is my_image.png, then writing my_image.png?random_number=54813778 would be treated as a different image.
Sep 10 '07 #2
I'm so glad, i found this Posts!
I had the same problem, and it took me 4 hours to find out what the deal is.
It even still exists in 2011 with IE8.
This is a horrible IE bug!

I cleared the cache, went to the temp-directory and cleared things by hand. I even reinstalled IE.
I have no idea where the hell IE is caching that file-size. Must be somewhere in the registry (?).

However, i attached a timestamp, generated by JS, to the filename.
Works fine.

Thanks alot!!!
Mar 16 '11 #3
This is great! And thx to Maik who confirms that's still a problem. Had been searching for 4h today too xD And thought I was going mad... especially when I found the real source of the problem. Since I'd had to look through different frameworks and ajax requests till i found where the size of the image is actually calculated... wasn't more than
var img = new Image();
img.src = "whatever.jpg";
That always gave me the wrong size.
And I totally went crazy when:
document.images[0].src = img.src;
was what I'd espected (added <img src=""> to the html first ;) ).
Now to read that's quite the experience others had too... what a relieve :)
I simply hate IEx!!!!
I'll try to add a timestamp to the source.
Jan 18 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Phil Powell | last post by:
I created a page that will be doing image resizing and manipulation, which seems to work (using GD library). However, upon returning to the page where the image has been changed, I still see the...
by: Mimo Zus | last post by:
I'm hoping that someone can explain what's going on; better yet provide a workaround. I'm designing a centered CSS site based on a 550 pixel wide vertical background image. Onto this background...
by: Hugh | last post by:
after I changed the image size. I tried different combinations of images sizes and button sizes. I have tried both botton and the image in the same sizes or button size was larger than that of...
by: ntombikayise | last post by:
Hi, I urgently need help. My code should let a user select an image file for upload, view the image on the browser to be able to set the image size then upload the image. It should also be...
by: bizt | last post by:
Hi, Is it possible to obtain the width/ height of an image when that image is dyanically created using a PHP script and passing GET attributes. For example: <img...
by: Tarik Monem | last post by:
OK! I've gone through a few tutorials and I cannot understand what I'm doing wrong casting_registration.php <table> <tr> <td> <form enctype="multipart/form-data" action="thankyou.php"...
by: .... www.FocusOnPanama.com .... | last post by:
I have an annoying problem with the site I am developing. This is how I see the problem appear: In a paragraph (<P>) I start with an IMG tag that has an 'align=left' OR 'align=right' (with the...
by: shapper | last post by:
Hello, I am displaying an image on a few pages. The image size is 50 px height and 50 px width. In some pages I need the image to be 30x30 px in others 40x40 px and in others 50x50px. Can I...
by: shapper | last post by:
Hello, I have been trying to create a simple feedback message do display on a web site. I am trying to have a message with an Icon on left and and Text on right. If possible both text and...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.