Follow by Email

Saturday, July 26, 2014

Loading image bypassing browser cache

In my JSP page I was using an img tag to load an image in my view page.

Problem :
<html:img page="/${}"   width="400" height="550" style="border:none" /> I was facing problems to load the latest image using above image tag , the browser was retrieving the cached image to me not the latest Below are the steps I was doing 
  1. update the image from my update page
  2. show the view page to the user , showing him the current image , but current image was not shown to the user instead the last loaded page from the cahce was being loded by browser.
I had the related no-cache meta tag in my page still I was facing this problem.


Apparently I found that it was the imag tag which was causing problem , since the browser was getitng the same link with no change it was loading the image from cahce , the only solution is to have unique link to load that URL by adding a uniquie value at the end of the link t load image , so I started appending the time stamo with the link and now it's working fine I can always see the lates image now , below is what I did in my JSP

<!-- Define date variable-->
<jsp:useBean id="current" class="java.util.Date" />
<!-- Append time at the end of image page -->
           <html:img page="/${}"}&a=${current.time}"   width="400" height="550" style="border:none" />
This will always make it a unique URL for browser hence it will not load the image from cache.

No comments:

Post a Comment