SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    May 2007
    Posts
    242
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Checking File Change via Ajax

    Hello. I check a XML file on my server. It is a big file so to save bandwidth, I first open a HEAD request then check the last-modified parameter of the XML file via getResponseHeader("last-modified"), after that if the file was changed, I retrieve the file normal way by opening another request (GET method). But for the task I use two ajax connections. I want to ask is there any other more efficient ajax way to download a file if it is only changed and at one request?

    Thanks.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, http supports conditional requests in the form of an if-modified-since request header. The web server is supposed to compare this value to the files last modified time, and only server the file if it's been modified since the time in the request header. Otherwise it replys with a 304 not modified header, and the browser would just continue to use the locally cached version.

    I would imagine that in order for a browser to be able to use this, the web server needs to not only send a last-modified header, but also a date header(to establish its notion of the time).

    Browsers definately send these conditonal requests very often. I've never bothered to check if they use them for ajax get requests though, but I really don't see why they wouldn't.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •