8

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

DavidG
  • 113,891
  • 12
  • 217
  • 223
cdugga
  • 3,849
  • 17
  • 81
  • 127

5 Answers5

9

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)

Daniel Rikowski
  • 71,375
  • 57
  • 251
  • 329
7

Use the document.lastModified Javascript property.

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

michaeljoseph
  • 7,023
  • 5
  • 26
  • 27
  • 4
    I'm wondering, how does the `document.lastModified` JavaScript property actually work? I didn't know JavaScript could see when you last edited the file. Do you know how it works? – Nathan Oct 08 '11 at 16:58
  • @Nathan It uses the `Last-Modified` header. – Toothbrush Apr 18 '15 at 19:55
3

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
  • 21,706
  • 2
  • 31
  • 35
2
<script type="text/javascript">
<!--
document.write(document.lastModified);
// -->
</script>
dogbane
  • 266,786
  • 75
  • 396
  • 414
1

There are some proposed meta tag keys representing Dublin Core values that may be used. See: https://stackoverflow.com/a/14893974/895245

Community
  • 1
  • 1
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985