Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting the list of supported image types in from a httpRequest?

Is it possible from a httprequest, to extract the image types/mimes, that the client browser support.

I know that it is possible determine what the browser is, and the preferred image type, but not a list of all the supported.

It this even possible?

I am currently trying to optimize the mediahandling of my page, Webscore indicate that nextGen image should be served, as the once served now are too big.

Serving nextgen is not that difficult, currently is all the nextgen version not supported by all the browsers, and support list is currently hardcoded in a switch case. It would be neat if the client browser could provide me with info regarding what it supports, rather than having a list that very likely might become outdated due to updates.

This is why I am seeking for browser media format compatibility list from the mediaRequest been sent.

like image 645
I am not Fat Avatar asked Jan 04 '19 11:01

I am not Fat


1 Answers

navigator.mimeTypes would only list you the browser supported types within the browser navigation scope at that time. For more reference;

navigator.mimeTypes Explained

browserContext Explained

As to my knowledge, there is no way of getting the browser specific full list with any existing api. Moreover, stack will not be compatible with other browsers as shown in compatibility diagram.

navigator.mimeTypes compatibility

Additionally, if getting the supported mime types through plugins collection of the browser (only supported on Chrome and Firefox) you can do something like;

var mimeCheck = function (type) 
{
    return Array.prototype.reduce.call(navigator.plugins, function (supported, plugin) {
    return supported || Array.prototype.reduce.call(plugin, function (supported, mime) {
                return supported || mime.type == type;
            }, supported);
        }, false);
}
like image 97
Ozan Gunceler Avatar answered Oct 13 '22 18:10

Ozan Gunceler