views:

54

answers:

2

I have an html page that is loading multiple iframes into which are embedded dynamic images created from a Tomcat server page (.jsp). This works as expected from Chrome and Firefox, but for some reason IE displays all of the images the same (as the first image). I've created an example:

http://coupondiscounts.com/jsImageTest.html

jsImageTest.html -- This page simply loads 6 instances of the testImageFrame.html page in separate iframes one-at-a-time, using Javascript.
testImageFrame.html -- This is the page loaded in all the iframes. It contains only a JavaScript block that writes out the current time and an img tag. The img is dynamically generated by a .jsp page on a different server. It should be a white box on a black background. In the box are the current time (from the Tomcat server using Java) and a randomly created double between 0 & 1.

What happens (in IE): The page almost instantly loads four identical iframes. Depending on the speed of your machine, the JavaScript times may vary by a second or two. The images' times will all be the same as will be the random number. This holds true even for the last two iframes which are loaded 5 and 10 seconds after the others (using JavaScript setTimeout()).
What should happen (as it does in Chrome and FF): The page loads the same 4 iframes, but the random numbers in the images will be different. The times in the images occasionally span a second as well.

Anyone have a clue as to what's going on here? Is IE doing some strange caching? The image header has "no-cache," "no-store" and all that. I've tried it on IE6 and 7. You can use the "Next" button to create another iframe. In IE, the images are always the same.

Notes: I don't really need iframes, just the images, but if I only use img tags, the problem appears in Chrome and FF as well. I also don't really need to load these iframes dynamically, I was just trying to abstract the issue further and allow a delayed load for the latter 2 images.

A: 

Pass a cache breaking variable, or set a no-cache header.

IE (no pun intended)

<%
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>
Aaron Harun
-1 as OP already stated they have tried these steps.
Jaymz
...Undid downvote for setDateHeader :)
Jaymz
I also said a cache breaking variable. Many browsers won't cache a page with `?` in the url. So he could use: http://hostname.com/mypage.jsp?time=sometime Edit: TY :)
Aaron Harun
I also have response.setDateHeader ("Expires", -1);The code here is test code. The actual code, which is much more involved does have query string parameters which are even different on each call. In other words, the full URL for each image is the same before the ? but unique afterwards. Either way, IE still displays them all the same.
rdevitt
Can you just use rewrites so that partly arbitrary urls hit your .jsp file? hostname.com/myfolder/uniqueimagename.jpg
Aaron Harun
Hmm... that's an interesting idea. Is there a way to do that with jsp? I assume you're still talking about dynamically creating them as image streams the same way as opposed to creating a temp image directory (I'd like to avoid that). So 'myfolder' in your example would be the actual page and would take '/uniqueimagename.jpg' as if it were a query string?
rdevitt
I was thinking you could use this: http://www.tuckey.org/urlrewrite/
Aaron Harun
I found the same. It looks like you might be on to something. I set up another test using this method, and it appears to work in IE. So, question, as asked: answered. However, I'm working on integrating it into my working code, and I seem to be having some of the same issues (although different now). I'll post back when I can fully confirm the solution.
rdevitt
No dice. Same issue. There must be something wrong with the Java code that's creating the image files. There's no reason that IE (or any browser) should interpret "http://domain.com/4879sdj8876/1.jpg" and "http://domain.com/4879sdj8876/2.jpg" as the same image and use the image cache from the first one for both. Right???? I'm going to rewrite my java code to see if the issue lies there.
rdevitt
Yah, with different file names they should be totally different images. The problem has to be somewhere else.
Aaron Harun
+1  A: 

MSIE is terrific when it comes to caching. The problem here is that it doesn't adhere the caching instructions as specified in the headers of the "parent" HTML page from where the JS code is executed.

Your particular issue can be solved by adding a timestamp to the query string.

ifr.src = 'testImageFrame.html?' + new Date().getTime();

This forces MSIE to fire a brand new GET request from JS on.

BalusC
This appears to be the same answer we've already discussed.
rdevitt
If this didn't solve the problem, then maybe you need to clear cache before re-testing :)
BalusC