7

I'm using the standard document.lastModified Javascript property to output the supposed last modified date of the page, but it's outputting the actual current date and time. Any clue as to why it'd behave this way as opposed to outputting the actual last modified property of the page? This happens both locally (on my machine) as well as the published page on the delivery server.

michael t
  • 390
  • 3
  • 11
  • The standard what now? That is DOM Level 0, and not standardized anywhere ? – adeneo Dec 18 '13 at 18:29
  • 2
    'Gets the date that the document was last modified, if the document supplies one.' Check the HTTP headers. – raina77ow Dec 18 '13 at 18:30
  • `lastModified` is a value in the response headers. Are you dynamically creating this resource on your server? – srquinn Dec 18 '13 at 18:34
  • i believe document.lastModified is simply the same time as the lastModified header, if it was sent, or the current time if the server omitted that header.. – dandavis Dec 18 '13 at 18:40
  • @adeno - the standard Javascript attribute "lastModified" of the document object. – michael t Dec 18 '13 at 19:44

2 Answers2

8

document.lastModified I imagine is based on the HTTP Response Header field Last-Modified (RFC2822). Last-Modified is usually used in conjunction with the Request header field If-Modified-Since for caching purposes.

Like other header fields, it's server implementation specific as to what value is returned. The server software replying to your HTTP Request might or might not return the Last-Modified header field in the HTTP Response.

In the pages you are running this on, the server simply returns the current date. Same is true for this page.

However execute document.lastModified (in Dev Tools) on say https://developer.mozilla.org/en-US/docs/Web/API/document.lastModified, you'll get 11/13/2013 09:13:29

Using firebug in Firefox or Chrome Dev Tools in Chrome, you can see inspect HTTP traffic data in the Network tab.

Community
  • 1
  • 1
cbayram
  • 2,259
  • 11
  • 9
0

Tested lastModified on a local file on my hard drive. Chrome returns current time/date and not when file was saved. Internet Explorer and Firefox return time/date file was saved. So this is a Chrome bug. Get page to check if Chrome from the userAgent and warn user or disable code.

Blockquote

if(navigator.userAgent.indexOf("Chrome/")>0){ alert("Chrome bug.\nPlease use a different browser.\nOne that works."); }

Blockquote

Other problems with lastModified. It returns a string and not a date object. So can't use date.getFullYear() The string is in the USA format and not the standard format of d/mm/yyyy