Solved

How do I avoid caching a image?

Posted on 2000-03-10
12
170 Views
Last Modified: 2010-04-09
Hi,

I would like to put a banner in my page but I don't want it to be cached(by neither proxy nor browser).

How can I do that by "pure" HTML or Javascript?

I don't have a lot of control, although I know an easy way to solve that is to use Server-sided scripts or HTTP headers.
0
Comment
Question by:jthsu
  • 8
  • 2
  • 2
12 Comments
 
LVL 8

Accepted Solution

by:
xabi earned 100 total points
ID: 2603731
Here goes the code.

------- 8< --------- 8< ------
<script languaje="javascript">
<!--
var now = new Date()
document.write("<img name='foo.gif?nocache=" + escape(now) + "' width='200' height='200'>"
//-->
</script>
------- 8< ---------- 8< -------

replace your <image ....> with my code and modify it to your image size and name.

xabi
0
 
LVL 8

Expert Comment

by:xabi
ID: 2603733
It's language, not languaje ... sorry (Typo)

xabi
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 2604779
Yes, and even simpler is:


<script languaje="javascript">
<!-- //
 document.writeln("<img name='myimage.gif?nocache=" + Math.random() + "' width='200' height='200'>" );
// -->
</script>


... that way you don't have to mess with a Date.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 2604783
... and as xabi noted, its "language"  ;)
0
 

Author Comment

by:jthsu
ID: 2605490
I put the following code in my HTML but i did not work...

<a href="http://media.exchange-it.com/click.go?b116995=1" target="_top">
<script language="javascript">
<!--
var now = new Date()
document.write("<img name='http://media.exchange-it.com/image.go?b116995=1?nocache=" + escape(now) + "' width='468' height='60'>"
//-->
</script></a>

I wonder if it's because of double question marks it has within the document.write.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 2605538
Try this:

document.write("<img src='http://media.exchange-it.com/image.go?b116995=1?nocache=" + escape(now) + "' width='468' height='60'>" );

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 33

Expert Comment

by:knightEknight
ID: 2605539
________________________________________________________________________________________________________________________
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 2605543
... I think the main things were:
1) missing parentheses at the end, and
2) you had "name" instead of "src"
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 2605547
... points should go to xabi, ofcourse
0
 

Author Comment

by:jthsu
ID: 2605600
Hi,

Now I can see the picture. But I still can't avoid the banner being cached.

Any other suggestion?

.....
<a href="http://media.exchange-it.com/click.go?b116995=1" target="_top">
<script language="javascript">
<!--
var now = new Date()
document.write("<img src='http://media.exchange-it.com/image.go?b116995=1?nocache=" + escape(now) + "' width='468' height='60'>");
//-->
</script></a>
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 2605620
Ah, I think I see the problem.
Try this:

<a href="http://media.exchange-it.com/click.go?b116995=1" target="_top">
<script language="javascript">
<!--
document.write("<img src='http://media.exchange-it.com/image.go?b116995=1&nocache=" + Math.random() + "' width='468' height='60'>");
//-->
</script></a>
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 2605625
... the problem being the "?" before "nocache" -- it should have been a "&".
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now