?
Solved

html refresh once again

Posted on 2004-11-04
19
Medium Priority
?
373 Views
Last Modified: 2008-01-09

i bet my life this has been asked a hundred times, so my apologies.

how can i make the web browser, check if a html page has been modified and make sure
the user is viewing the latest version.

i' am not refering to a simple meta-refresh or expires,,  is there a way to make the browser
check and compare the last modified time of the html file say every 60 seconds,, but not
refresh the display ( as this produces flicker ) if the html file is unchanged..

thankyou

ashod apakian
0
Comment
Question by:apakian
  • 11
  • 8
19 Comments
 
LVL 30

Expert Comment

by:VirusMinus
ID: 12495060
0
 
LVL 30

Expert Comment

by:VirusMinus
ID: 12495161
If you can use ASP this is a nice way to do it ->
<%
'prevent any cache issues occuring by putting this at the top of the page
Response.Expiresabsolute = Now() - 1
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"  
Response.AddHeader "cache-control","private"
%>

Some more info here -> http://www.experts-exchange.com/Web/Web_Languages/HTML/Q_10103831.html
0
 

Author Comment

by:apakian
ID: 12495217

> am not refering to a simple meta-refresh or expires,,  is there a way to make the browser
> check and compare the last modified time of the html file say every 60 seconds,, but not
> refresh the display ( as this produces flicker ) if the html file is unchanged..

example:

somedays i update my index.html once a day,, and on some days i update once every 10 minutes..

i want the following

1) users opens IE, and goes to htp://www.mysite.com/index.html
2) browser gets index.html , displays it to the user and stores it in its cache
3) somehow index.html tells the browser, to check if it has been modified every X seconds
4) every X seconds, the browser checks if index.html has been, if its been modified goto step 2
5) reset timer, goto step 4

most important thing is, if the page has not been modified, i dont want to browser to refresh the
display..

setting the meta-refresh to say 30,, will cause the page to reload every 30 seconds, regardless,
which is annoying.. i just want a reload only when the page has been updated.

0
Technology Partners: 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 30

Expert Comment

by:VirusMinus
ID: 12495528
i think this what you're trying to do but via script ->

In IE:
1. Click Tools, then Options
2. Under the General tab, click 'Settings'
3. Click the radio button next to "Every visit to the page"

Other browsers have similar settings.

To do this via script you need wither applets or XML, there maybe other ways but they can be more complicatd to implement. You're looking for the server to intitate the refresh. This is called a Server Push..

Here are some links about the same ->
http://www.15seconds.com/issue/971102.htm
http://www.antipope.org/charlie/attic/webbook/ch3http/part7.html
http://wp.netscape.com/assist/net_sites/pushpull.html
http://www.cs.sfu.ca/CourseCentral/365/li/material/slides/A21.html
http://www.via.ecp.fr/~vbp/test/serverpushvbp.html
http://webclass.csuchico.edu/courses/advweb/notes/server-push/index

0
 
LVL 30

Expert Comment

by:VirusMinus
ID: 12495550
Here's someone who made progress doing it via XML

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20082233.html
0
 

Author Comment

by:apakian
ID: 12495609
In IE:
1. Click Tools, then Options
2. Under the General tab, click 'Settings'
3. Click the radio button next to "Every visit to the page"

Other browsers have similar settings.

this is an setting of the browser..........

please look at point 3)


>> 3) somehow index.html tells the browser, to check if it has been modified every X seconds

it would be completely impracticle to send an email out to all our users suggesting they
set some setting their browser.

explaining a problem is not my strong point :-)

in a nutshell, i want the browser to only re-download and re-display a html page only when it's last
modified field differs from the last modified field in it's cache...

0
 
LVL 30

Expert Comment

by:VirusMinus
ID: 12495611
ok there seems to be a way, read this Q and try the javascript;

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20083788.html
0
 
LVL 30

Expert Comment

by:VirusMinus
ID: 12495657
I understood your problem, I mentioned that the IE setting is what you want to emulate but via code. Read my posts and follow the links. The way to do it seems to be via applets, XML or a javascript function.

-VM
0
 

Author Comment

by:apakian
ID: 12495789


i understamd, but Q_00083788.html refers to

"using reload is the same call, except reload will load from cache unless the page has the page cache disabled."

the cache issue is not my primary concern:

using 'c' code , i can write a small function that sits in a loop and calls a GET to a particular url every
X seconds, with the field If-Modified-Since: Nov 05 ......

assuming im a browser , if i get a 304 then  i do nothing,, and i do not refresh the users page,
if i do get a 200, then i get the lasted copy, refresh the users page update the lastmodified to
what the lastmodified was of the latest file i just downloaded and start the whole loop again.


0
 
LVL 30

Expert Comment

by:VirusMinus
ID: 12496031
Found this pdf, is interesting.

http://www.bluecoat.com/downloads/files/BCS_create_cachefriendly_website.pdf

Also, do you have control of the webserver where your web pages will be hosted? Do you know what webserver is running? IIS or something else?
0
 

Author Comment

by:apakian
ID: 12496118

is i have a dedicated server at servermatrix, with root access, there is no firewall or proxy, they
just give me an ip..

for web, im using apache 2 ( i think there is perl and fastcgi installed ), but i need
to achieve the solution, by client-side coding, as some of our pages will be served
from other server not-owned by us.


0
 
LVL 30

Expert Comment

by:VirusMinus
ID: 12496183
I don't think there is a way to do what you want client side only. some initiation from the server is required.
0
 

Author Comment

by:apakian
ID: 12496246

firstly,, that pdf.link is very very good..

where do you see any initiation from the server...

the psuedo-code i've supplied is completely stateless, excluding local timers on
the client-side, which are obviously implemented in the javascript or html handlers.

i dont know 'html' or 'javascript', but ive written http servers and clients in c.

a http client ( the web browser ), periodically connects to the http server, and
requests a file to be downloaded if the lastmodified fields differ..

the http server, sits in a loop forever waiting for http clients to connect to it.

i see no initiation from the server, in my question.. can you please clarify..



0
 
LVL 30

Expert Comment

by:VirusMinus
ID: 12496575
Okay i think I understand now, The last-modified header could be used to do what you want. Fortunately Apache supports reading of this header i think. refer ->
http://www.web-caching.com/mnot_tutorial/notes.html
http://httpd.apache.org/docs/mod/mod_expires.html
http://www.mit.edu/~yandros/doc/cache_doc.html
http://www.html-faq.com/serverbasics/?caching
0
 

Author Comment

by:apakian
ID: 12496772

im reading them now,, the documents

http://www.web-caching.com/mnot_tutorial/notes.html
http://httpd.apache.org/docs/mod/mod_expires.html

are issues covering server side, so those solutions are  redundant.
the other 2 documents, like the first look very written, concerning
caching ( i'd really like a copy of your bookmarks )..

i will quickly jot through them, but ive got a feeling it's
not quiet what i want,, brb..


0
 

Author Comment

by:apakian
ID: 12497046

http://www.mit.edu/~yandros/doc/cache_doc.html

gave me the answer, in a few steps more than anticipated...

i think if i use

Cache-Control: max-age=60, must-revalidate

every 60 seconds it will force the browser to check if the file has been modified,, i am
assuming and hoping that if it has NOT, then the web browser will result the timer
and check again after another 60 seconds; this solves the main problem.. thankyou..

however, i do not know if this happens at the presentation layer or the transport layer:
the reason i mention this; is if this solution is at the presentation/html layer, than
i am certain, it will cause the display to be refreshed even if the file has not changed,
 ( display refreshed meaning, just redraw the one from the cache )...

can i prevent this,, as even though more a cosmetic and issue, it would wrap
this problem up for me, if i can restrict the refreshing of the page when and only
if the page has been modified..

if i acccept your answer now, can we still communicate ?






0
 
LVL 30

Accepted Solution

by:
VirusMinus earned 1200 total points
ID: 12500486
I wasn't so sure myself about the redraw, but i've found some more links (yes i searched for them , they're not bookmarks) I've learnt so much from researching this topic.

This excerpt is from this article http://www.sitepoint.com/print/php-anthology-2-5-caching which suggests that it is possible to not redraw the page based on a last-modified check

"Page Modification Time
---------------------------------
A more useful approach is to make use of the Last-Modified and If-Modified-Since headers, both of which are available in HTTP 1.0. Technically, this is known as performing a conditional GET; whether you return any content is based on the condition of the incoming If-Modified-Since request header.

Using this approach, you need to send a Last-Modified header every time your PHP script is accessed. The next time the browser requests the page, it sends an If-Modified-Since header containing a time; your script can then identify whether the page has been updated since the time provided. If it hasn't, your script sends an HTTP 304 status code to indicate that the page has not been modified, and exits before sending the body of the page.

Providing a simple example of conditional GETs is tricky, but PEAR::Cache_Lite is a handy tool to show how this works. Don't get confused though; this is not meant to show server side caching; it simply provides a file that's updated periodically.

Here's the code: "

Here's another excerpt from (read the discussions below as well) -> http://simon.incutio.com/archive/2003/06/21/caching
"The Expires header is a mixed blessing. If you are sure that your content will not change, or you are fine with people getting out of date objects, then by all means, go ahead. But what most people want is 'must-revalidate', which means that browsers/proxies can still cache the documents, but they need to validate their copy before presenting it to the end user. By 'validate', I mean "check it is up to date" (this is different to HTML validation).

To check that their copy is up to date, they can send a couple of extra headers when requesting the object. The server then has the freedom to send back a 304 Not Modified response. This is something that is done automatically by Apache for flat files (hence the appeal of "funky caching"). However, if you are generating your content via PHP, you have to explicitly code the check and response. "

some code was also posted here -> http://www.sitepoint.com/forums/showthread.php?threadid=114882

Another excerpt from this excellent article -> http://www.mnot.net/cache_docs/
"I’ve marked my pages as cacheable, but my browser keeps requesting them on every request. How do I force the cache to keep representations of them?

Caches aren’t required to keep a representation and reuse it; they’re only required to not keep or use them under some conditions. All caches make decisions about which representations to keep based upon their size, type (e.g., image vs. html), or by how much space they have left to keep local copies. Yours may not be considered worth keeping around, compared to more popular or larger representations.

Some caches do allow their administrators to prioritize what kinds of representations are kept, and some allow representations to be “pinned” in cache, so that they’re always available"

some more articles ->
http://www.httpsniffer.com/http/1302.htm
http://kavlon.org/index.php/website
http://www.zend.com/codex.php?id=435&single=1
http://www.webmasterworld.com/forum93/168.htm
http://www.phpbuilder.com/lists/phplib-dev-list/199911/0062.php
http://www.php.net/manual/en/function.session-cache-limiter.php
http://au.php.net/header
http://www.php.net/manual/en/function.session-cache-limiter.php

I quickly scanned these, but you may want to read them oin detail.


In summary it seems possible not to 'redraw' the page but refresh it only on modification (vague evidence), although you may have to choose from a variety of methods...

But you may have some flickering which may look like a redraw?

and yes we can still comminicate after you accept an answer. Email notifications continue unless someone unsubscribes from the question.
0
 

Author Comment

by:apakian
ID: 12501019

this is going to keep me busy this weekend:

my hat of to you, thankyou for the great info..

0
 
LVL 30

Expert Comment

by:VirusMinus
ID: 12502234
Cheers!
-VM
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

580 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