0

With the code below I'm able to read, and log to the console, the contents of a file (myfile.txt) hosted on-line on the same folder/server as the HTML page with such code.

<!DOCTYPE html>
<html>

<script>

async function doIt()
{
  let response = await fetch("myfile.txt", {cache: "no-store"});
  let contents = await response.text();
  console.log(contents);
}
    doIt();

</script>

</body>
</html>

My problem is that instead of the file contents I want to log the date/time when such file (myfile.txt) was last modified and I can't find the way to do it.

What am I missing? Would it be possible? How?

Many thanks in advance for any help!

  • There is a header that can give this information Last-modified, what server are you using? – peter duffy Jul 13 '22 at 18:50
  • https://stackoverflow.com/questions/2313620/is-it-possible-to-retrieve-the-last-modified-date-of-a-file-using-javascript – Woodsy Jul 13 '22 at 19:03
  • @peterduffy, I'm using an Italian service provider: www.aruba.it. Would the functionality I'm trying to achieve be "server dependent"? Thanks and regards – EuRobot Jul 13 '22 at 19:38
  • 1
    @Woodsy, many thanks for your input! I've tried the fetch method as suggested by FutureBoy and it works fine. – EuRobot Jul 13 '22 at 19:59

0 Answers0