473,396 Members | 1,891 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,396 software developers and data experts.

IE caches wrong image sizes

1
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.

http://www.ailis.de/~k/permdata/20070910/iebug/

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:

http://www.ailis.de/~k/permdata/2007...bug/works.html

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 3893
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";
alert(img.width);
That always gave me the wrong size.
And I totally went crazy when:
document.images[0].src = img.src;
alert(document.images[0].width);
alert(img.width);
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.
Thx!
Jan 18 '12 #4

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

Similar topics

5
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...
4
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...
9
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...
1
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...
2
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...
2
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"...
13
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...
11
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.