问题
Can I get an image's file size and mime-type via JavaScript. I am writing a script for inspecting all images in a document. I will run the script in FireFox only so a solution specific to FireFox (undocumented/non-standard/otherwise) is perfectly acceptable. I can use jQuery if necessary.
回答1:
You could make a HEAD
request with XHR which will tell you the file size, provided these images are on your domain.
回答2:
you can do it through HTTP head request
var request;
request = $.ajax({
type: "HEAD",
url: 'your image url',
success: function () {
alert("Size is " + request.getResponseHeader("Content-Length"));
alert("Type is " + request.getResponseHeader("Content-Type"));
}
});
来源:https://stackoverflow.com/questions/5456245/can-i-get-an-images-file-size-and-mime-type-via-javascript-firefox-gecko-mozil