Solved

How do I avoid caching a image?

Posted on 2000-03-10
12
175 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

695 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