473,799 Members | 3,339 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 3143
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
2063
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
19195
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
4215
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
7597
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
1882
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
1605
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
3676
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
2723
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
12469
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
9687
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
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10251
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10228
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
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...
0
6805
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
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2938
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.