views:

1724

answers:

6

Hi guys,

how can i figure out the last modified date of a html file im importing into my web app?

The html file is on another server and different users can make updates, when i retrieve the page i want to be able see when it was last updated so i can label the updated date on my homepage. I

+3  A: 

Use the document.lastModified Javascript property.

quirksmode has a nice function to format the date too: http://www.quirksmode.org/js/lastmod.html

michaeljoseph
+1  A: 

You could use the Last-Modfied Header from the response headers.

The Last-Modified entity-header field indicates the date and time at which the origin server believes the variant was last modified.

   Last-Modified  = "Last-Modified" ":" HTTP-date
Node
A: 
<script type="text/javascript">
<!--
document.write(document.lastModified);
// -->
</script>
dogbane
+2  A: 

I assume you are using HTTP to retrieve the page.

In that case you can use the HEAD method of HTTP to get the header data of the file. (See http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html, 9.4)

Then you can check the "Last-Modified" header of the response. (See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html, 14.29)

In case of some caching mechanism (proxy, browser caching) it might be necessary to include "Cache-Control: must-revalidate" in the request header. (See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html, 14.9.4)

DR
A: 

ok cool, im using httpclient then to retrieve the content, would i need something like the following to retrieve the date?

Header lastModified = GetMethod.getResponseHeader("Last-Modified");
combi001
A: 

i have tried this approach but the updated date showing on my page is a day behind the actual date the file was last modified on (the date which appears next to the file name on the server). I am using caching, is it possible that this is having some effect because when i dont use caching it works fine?

combi001