473,713 Members | 2,673 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to refresh cached image ONCE

Hi all,

I have an application which generates image graphs. These cache nicely
at the client, however if the user submits more data, I'd like to
force a reload of the image from the server.

I had a google, but all I could find were suggestions to use a varying
query in the URL. This is not a solution to my problem because if I
change the page to do that then ALL the graphs will be reloaded every
time.

I tried

document.getEle mentById("imgs_ id_tag").src.re load():

and

document.getEle mentById("imgs_ id_tag").reload ():

But just got errors.

(If I open JUST the image URL in a browser, I get the cached version,
if I then click on refresh, it goes back to the server to get a new
copy - which is what I want).

Any suggestions?

TIA

C.
Jul 18 '08 #1
32 3130
you can try this...

var elem = document.getEle mentById("imgs_ id_tag");
var oldSrc = elem.src;
elem.src = oldSrc + '?rnd=' + new Date().getTime( );

This basically says "set the src to the exact same thing, with an
aditional 'random' parameter (current date/time as a number)"

HTH
Jul 18 '08 #2
On Jul 18, 7:06*pm, "C. (http://symcbean.blogsp ot.com/)"
<colin.mckin... @gmail.comwrote :
Hi all,

I have an application which generates image graphs. These cache nicely
at the client, however if the user submits more data, I'd like to
force a reload of the image from the server.

I had a google, but all I could find were suggestions to use a varying
query in the URL. This is not a solution to my problem because if I
change the page to do that then ALL the graphs will be reloaded every
time.

I tried

document.getEle mentById("imgs_ id_tag").src.re load():

and

document.getEle mentById("imgs_ id_tag").reload ():

But just got errors.

(If I open JUST the image URL in a browser, I get the cached version,
if I then click on refresh, it goes back to the server to get a new
copy - which is what I want).

Any suggestions?
image.src+= "?"+Math.random ();

--Jorge
Jul 18 '08 #3
On 18 Jul., 19:06, "C. (http://symcbean.blogsp ot.com/)"
<colin.mckin... @gmail.comwrote :
Hi all,

I have an application which generates image graphs. These cache nicely
at the client, however if the user submits more data, I'd like to
force a reload of the image from the server.

I had a google, but all I could find were suggestions to use a varying
query in the URL. This is not a solution to my problem because if I
change the page to do that then ALL the graphs will be reloaded every
time.

I tried

document.getEle mentById("imgs_ id_tag").src.re load():

and

document.getEle mentById("imgs_ id_tag").reload ():

But just got errors.

(If I open JUST the image URL in a browser, I get the cached version,
if I then click on refresh, it goes back to the server to get a new
copy - which is what I want).

Any suggestions?

TIA

C.
Hi,

You should send right http headers to the client.

More about this: http://developer.yahoo.com/performance/rules.html
under Add an Expires or a Cache-Control Header

;)

Best,
Stanislav
Jul 18 '08 #4
we*********@gma il.com wrote:
you can try this...

var elem = document.getEle mentById("imgs_ id_tag");
The `images' collection should be used instead:

var elem = document.images["imgs_id_ta g"];
var oldSrc = elem.src;
What for?
elem.src = oldSrc + '?rnd=' + new Date().getTime( );

This basically says "set the src to the exact same thing, with an
aditional 'random' parameter (current date/time as a number)"
Because it is not considered the same thing by the user agent, it will fill
up its cache (if enabled), leaving less space for other, maybe more
important data.

Also, a random value alone is not sufficient; it must be a value that is
unique over a longer period of time, like the timestamp that you suggested.

Cache-controlling HTTP headers are the correct approach instead.

Please do a little research before you post something here.

<http://jibbering.com/faq/>
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Jul 18 '08 #5
On Jul 18, 7:50*pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
>
Also, a random value alone is not sufficient;
Yes it is, Thomas, remember that the OP said that he wanted to reload
the image *once*.
it must be a value that is
unique over a longer period of time, like the timestamp that you suggested.
The probability of obtaining the same ramdom number twice in a row is
about 1/(2^(8*8)) === 1/184467440737095 51615
And keeps being almost null even after tens or hundreds of
extractions.

If you want to experiment how long that period of time can be, try
this : it will hang your browser until Math.random() repeats a certain
value :-)

javascript:n= 0, a= Math.random();w hile(a !== Math.random()){ n+
+};alert(n);

--Jorge.
Jul 18 '08 #6
On Jul 18, 7:50*pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
>
Cache-controlling HTTP headers are the correct approach instead.
Right. Cache-control headers ought to be explicitly setup just for
these images. Agreed.

But the OP was looking for a client-side solution, and that's not.

And the proposed solution will get the image reloaded regardless of
the (cache control) headers sent/received.
Please do a little research before you post something here.
Grrr.

--Jorge.
Jul 18 '08 #7
On Jul 18, 9:16*pm, Jorge <jo...@jorgecha morro.comwrote:
>
javascript:n= 0, a= Math.random();w hile(a !== Math.random()){ n+
+};alert(n);
On my Mac it took 2,147,483,645 iterations to get "a" repeated.

--Jorge.
Jul 18 '08 #8
Jorge wrote:
Thomas 'PointedEars' Lahn wrote:
>Cache-controlling HTTP headers are the correct approach instead.

Right. Cache-control headers ought to be explicitly setup just for
these images. Agreed.

But the OP was looking for a client-side solution, and that's not.
| I have an application which generates image graphs. These cache nicely
| at the client, however if the user submits more data, I'd like to
| force a reload of the image from the server.

Not a single word about a client-side only solution.
And the proposed solution will get the image reloaded regardless of
the (cache control) headers sent/received.
The server must send an appropriate expiry value and ETag in the headers,
and the client must refresh the images often enough. If the expiry date was
met, the ETag changed or the resource was not in the cache in the first
place, it would be downloaded (again) from the server; if not, the cache
would be used. ISTM anything else would require a server-push communication
like Comet.
>Please do a little research before you post something here.

Grrr.
Now I have given you a reason for that.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jul 19 '08 #9
On Jul 19, 3:48*am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
Jorge wrote:
Thomas 'PointedEars' Lahn wrote:
Cache-controlling HTTP headers are the correct approach instead.
Right. Cache-control headers ought to be explicitly setup just for
these images. Agreed.
But the OP was looking for a client-side solution, and that's not.

| I have an application which generates image graphs. These cache nicely
| at the client, however if the user submits more data, I'd like to
| force a reload of the image from the server.

Not a single word about a client-side only solution.
Does this look like server-side scripting to you : (?)

"I tried document.getEle mentById("imgs_ id_tag").src.re load(): "
"and document.getEle mentById("imgs_ id_tag").reload (): "
(...)
ISTM anything else would require a server-push communication
like Comet.
Duh !

--Jorge.
Jul 19 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2058
by: dogeater | last post by:
I've done hours of research but I can't seem to find an answer to a very simple problem. I have a catalog site where a user can upload an image for a certain product. He/she edits the product by uploading a different image. The problem is that the image is being cached and it doesn't get refreshed unless a user manually refreshes his/her browser. I've tried HTTP headers, Meta tags, htaccess and javascript. How are you guys doing...
2
19191
by: jeff | last post by:
Hello, I'm building an internal web application using HTML/PHP/Javascript. The system is flexible to the point where the user can have as many browser windows open for each part of the system. I would like a browser window that has just gained the focus to refresh. Is this possible and how? Thanks,
16
4203
by: DraguVaso | last post by:
Hi, I have a Windows Service running (made in VB.NET), and wanted to be able to change from time to time some parameters by changing them in the App.config. But it seems that the application doesn't use the changed values in the App.config, but continue to use the values that were there during start-up. Is there a way to let the application use the new values in the App.config? Is there kind of some 'refresh' function that I should...
4
7592
by: Lex | last post by:
I want to reload a page only once. Therefor meta refresh is not suitable, because then it refreshes every x seconds. Is there a possibility to refresh only once? regards, Lex Ouburg
10
1869
by: cosmic foo | last post by:
I have a page with about 100 images of about 10k each. where a typical img tag looks like this, <img src="item001.jpg" height="70" alt="" onMouseOver="showPic(this)" border="0"> Not all the images need to be viewed at once, depending on what category is selected, only about 10 images are seen at any one time. I hide and show categories of images by setting a div container display:none/block or visibility:hidden/visible. Even though the...
3
1604
by: Paul Johnson | last post by:
I have a web site that allows users to upload images. The problem is when an image is uploaded over the top of another image the user would have to press F5 to refresh the images and clear the cashe. Is there anyway I can automatically make the image refresh? If that is not possible is there a way of making the whole page refresh automatically?
6
3671
by: David | last post by:
Hello. I have such problem: I have ImageButton on my form which is attached to some image like "image.jpg", now when I change image file (physically file) with some other file with the same name my page shows the old image until I click "Refresh" button of the browser. So how can I refresh web form from code? Or may be there is some other way to solve this problem?
2
2720
by: Just D. | last post by:
All, How should we refresh the current aspx frame? I disabled caching using this command on Page_Load(): Response.Cache.SetCacheability(HttpCacheability.NoCache); but it didn't help. The problem is that this page shows the client Logo image, then asks to upload a new one if required, finally it should show the uploaded picture. The problem is that it doesn't. If I press F5, then I can see the updated
11
12461
by: nuhura01 | last post by:
Hi.. I have a button to preview image using the following code, which preview the image in html page: Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
0
8794
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9300
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5942
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4713
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2101
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.