1

For a web application which can run offline, I have a cache manifest file that contains a comment to indicate when it was last updated:

# version: 20131220-1006

I'd like to be able to read this version comment line so that I display the version number. Is there a way to get this directly through JavaScript?

(A workaround would be to create a server-side script that will read the version number from the cache manifest file stored on the server, and return that information as a separate operation, but that seems like sledgehammer+nut).

James Newton
  • 6,623
  • 8
  • 49
  • 113
  • Javascript can't do file i/o. Unless i've misunderstood, and you're storing the data in localstorage. – Julio Dec 20 '13 at 15:11
  • I understand that, on certain browsers, [JavaScript can do file i/o](http://www.html5rocks.com/en/tutorials/file/dndfiles/). – James Newton Dec 20 '13 at 15:23
  • The File API works on files on the client system, the cache manifest resides on the server. If you ever want to expose server data to the client, you must create a service for security reasons. – Mister Epic Dec 20 '13 at 15:33
  • @ChrisHardie: I understand that the cache manifest file is downloaded to the client and that its contents are available to the browser. Could you help me to understand why it would be a breach of security to make its contents accessible to JavaScript running in the browser? – James Newton Dec 20 '13 at 16:05

1 Answers1

1

You can not read this version number directly from javascript, but you can actually read content of cache manifest file. Load it with ajax request (jQuery version):

    $.get("cache.manifest", function(responseText){
        console.log(responseText);
    })
    .fail(function() {
        console.log( "Offline?" );
    });

You can fetch version from responseText string and save it localstorage. In offline mode you can read value from storage assuming it didnt change.

MDerks
  • 123
  • 5