The HTTP headers aren't available in JavaScript.
However you could use XMLHttpRequest
to do a HEAD
request to any resource within the same domain:
var xhr = new XMLHttpRequest();
xhr.open('HEAD', '/', true); // Relative path of resource
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
console.log(xhr.getAllResponseHeaders());
}
}
xhr.send(null);
The above will return something like this (running it in Firebug on this page):
Server: nginx
Date: Fri, 09 Jul 2010 18:58:30 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Cache-Control: public, max-age=60
Content-Length: 33273
Content-Encoding: gzip
Expires: Fri, 09 Jul 2010 18:59:31 GMT
Last-Modified: Fri, 09 Jul 2010 18:58:31 GMT
Vary: *
You can easily get the value of single headers like this:
xhr.getResponseHeader('Last-Modified');