Theoretically, you could use XHR to request an HTTP HEAD and check the Content-Length in the response headers.
A HEAD request is identical to a regular GET request except the server SHOULD NOT return the actual content. In other words, the server responds with headers that you would try a GET resource, but then stop and not send the file.
However, some responders respond to a HEAD request with a Content-Length 0 header, regardless of the actual file size. Others respond by file size.
To do this, you will need to pray that your server will return the actual file size to the HEAD request.
If so, getting this value is easy :
$.ajax('/myfile.js', { type: 'HEAD', success: function(d,r,xhr) { fileSize = xhr.getResponseHeader('Content-Length'); } });
Note that the JSFiddle server always returns 0 when we HEAD / , although / is 16916 bytes.
Also note that jQuery docs talks about an HTTP request type option:
Type of request ("POST" or "GET"), by default - "GET". Note. Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers.
I just tested this script in IE 6-10, Firefox 3.6-7, Opera 9-11, and Chrome, and each individual browser correctly issued a HEAD request, so I would not have to worry about this vague incompatibility statement. More to worry about how your server reacts.