I'm trying to get the content-type of an image from an image object. I know that it is possible to fetch it with a HEAD
request:
fetch(img.src, { method: 'HEAD' })
.then(response => response.headers.get('Content-type'))
This approach however does not really make use of browser caching / priorities of assets etc.
Instead, I would like to use the native images object:
const img = new Image();
img.src = url;
img.onload = ev => {
// figure out mime type here?
};
But I'm not sure how to get the image type here?