The best way to do this is with an AJAX HEAD request. HEAD requests only ask for and return the header from the destination file, so they’re much faster than POST or GET requests. Perfect for a simple file check.
It’s also worth noting that a HEAD request also returns the content length and last modified date, and that jQuery has an “ifModified” option for the .ajax function that returns a boolean value.
Quick code snippet:
$.ajax({ url:'http://www.example.com/somefile.ext', type:'HEAD', error: function(){ //do something depressing }, success: function(){ //do something cheerful :) } });
Couldn’t be easier!
Date: Wednesday, January 6th, 2010
Category: Web Dev