I feel like this is too much to be doing client-side, but I don't know the details of your application, so presuming you have to do it with jQuery... you can do a HEAD request and look at the Content-Length header. Earlier I recommended the jqHead plugin, but after I tried to use it I found that it was broken.
Here's a working example that doesn't depend on any extra plugins: http://host.masto.com/~chris/so/jqhead.html
The meat of it is very simple:
var request;
request = $.ajax({
type: "HEAD",
url: $("#url").val(),
success: function () {
alert("Size is " + request.getResponseHeader("Content-Length"));
}
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…