I would like to determine if a given URL is an image without relying on the file's extension. In JavaScript, is there a way to get a URL's HTTP response headers without retrieving the entire contents of the file?
Asked
Active
Viewed 170 times
1 Answers
3
You can do an http HEAD. This is covered in Accessing the web page's HTTP Headers in JavaScript
The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. This method can be used for obtaining metainformation about the entity implied by the request without transferring the entity-body itself. This method is often used for testing hypertext links for validity, accessibility, and recent modification.

Community
- 1
- 1

The Archetypal Paul
- 41,321
- 20
- 104
- 134