Click to See Complete Forum and Search --> : cache the images


sekhar2000
April 8th, 2002, 10:10 AM
DEar Friends,
Did you find the following requirement at any time....

we have a login web page(It was in JSP and the html part) with 12 Images and some other pages.

User first will login into the login.jsp page and move forward to the other pages.My question is when he back to the login page I have to show the images from cache instead of loading them again from the server.

Could you please give me your suggestion about how to handle this?Otherwise it is taking a lot of time to retrive the images again and again from the server.

REgards
chandu
chandrak@infotech.stph.net

websmith99
October 8th, 2002, 10:53 PM
The browser should cache the images by default.

If you ever run into the OPPOSITE situation with regard to caching (ie- you want to make sure the browser does NOT cache a particular page because you want to ensure the user gets the latest data) then here's a foolproof way:

Append a random number as a value to a query string parameter. That way the URL is unique each time and the browser will not be able to cache the page. This is neccessary as the <meta> tags for no caching are not reliable.


<html>
<head>
<script language="JavaScript" type="text/javascript">
random.m = 714025;
random.a = 4096;
random.c = 150889;
random.seed = (new Date()).getTime() % random.m;

function random() {
random.seed = (random.seed * random.a + random.c) % random.m;
return Math.round((random.seed / random.m) * 1000);
// This will generate a random integer between 0 and 1000. If you
// want to increase the range to between 0 and x, replace the
// "1000" in the above line with "x"
}
</script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
document.write('<a href="page2.jsp?foo=' + random() + '">Page 2</a>');
</script>
</body>
</html>


:cool:

Waldo2k2
October 9th, 2002, 11:11 PM
yeah like he said it will cache them....
if you ever get to a spot where you want them loaded prior to being at a page do this

var images=new Array();
images=['one.gif','two.gif','etc.gif'];

that code downloads the pictures to the cache....note: i'm not sure on those [ brackets ] ...may be ()