It is common knowledge that the document.lastModified
function returns a string containing the date and time when the current document was last modified.
Is it possible to obtain the Last-Modified for a script?
Here is an example of HTML code:
...
<script id="myapp" type="text/javascript" src="https://test.asl.cloud/cc/js/my-app.js"></script>
...
<button onclick="myFunction()">Try it</button>
<p id="test_doc"></p>
<p id="test_js"></p>
...
This is the Javascript code involved:
myFunction = function() {
var x = document.lastModified;
document.getElementById("test_doc").innerHTML = x;
var se = document.getElementsByTagName('script');
var s;
for (var i = 0; i < se.length; i++) {
if (typeof se[i].src !== 'undefined' && se[i].src.match('cloud')) {
s = se[i];
break;
}
}
console.log(s);
x = s.lastModified;
document.getElementById("test_js").innerHTML = x;
}
If you want to see this code in action, check out this JSFiddle link.