Solved

How do I avoid caching a image?

Posted on 2000-03-10
12
169 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

708 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

17 Experts available now in Live!

Get 1:1 Help Now