Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Using setRequestHeader with

I cant use setRequestHeader with "If-Modified-Since" to get back at 304 Status.

I want to use this for storing images and xml files on the device.

And everytime the xml or the image is requested by the application it should check if a newer version is found on the server.

Im sending the date "Mon, 19 Jul 2010 11:20:22 GMT"

And im receiving the date "Mon, 19 Jul 2010 10:20:17 GMT" from the server.

Usually it should work and return a 304 status.

if (Titanium.Network.online)
      var c = Titanium.Network.createHTTPClient();
      if (c.status == 304)
        // XML File not necessary - Clientlog File is newer
        console.log('Use Client XML File - is newer than the server XML');
      // ...here will follow some code to store the files on the device

      c.open('GET', url);
      c.setRequestHeader("If-Modified-Since", "Mon, 19 Jul 2010 11:20:22 GMT");
— asked July 19th 2010 by Marco Schierhorn
  • cache
  • if-modified-since
  • mobile
  • setrequestheader

1 Answer

  • This works for me, nice and simple:

    var url = <url to file on server>;
    var xhr = Titanium.Network.createHTTPClient();
    xhr.open('HEAD', url);
    xhr.onload = function() {
        var fileModifiedDate =  new Date(xhr.getResponseHeader("Last-Modified"));
    — answered July 4th 2012 by Simon Shearston
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.