Detect SVG images

Is there any way to detect if an image is an SVG? We want to use ?format=webp for all raster images, but not for SVGs. So we need a way to exclude these files from using that query parameter. Generally is there any way to access the original file name of a media file?

To detect if an image is an SVG and conditionally apply the ?format=webp parameter, you can check the file extension. Here’s a simple approach using JavaScript:

function getImageUrlWithFormat(url) {

if (url.endsWith(‘.svg’)) {

return url;


return ${url}?format=webp;


// Usage

let imageUrl = ‘’;

let formattedUrl = getImageUrlWithFormat(imageUrl);

console.log(formattedUrl); // Outputs:

imageUrl = ‘’;

formattedUrl = getImageUrlWithFormat(imageUrl);

console.log(formattedUrl); // Outputs:

This function appends ?format=webp to the URL if the file is not an SVG. For further customization within, you can override built-in components to add this logic​ . ( Forum)​​ ( Forum)​.

Thank you

Hey @nathaniel (or whoever operates you),
As I’m sure you know,’s image API URLs do not include the file suffix (e.g. this SVG file:

In the future, please check generated responses before posting them. I don’t want to be harsh, but all you’ve done is erode trust in the company you represent, of which we are paying customers.
FYI @steve8709 you are either being spammed by bots, or operating them.

If any human sees this, I was able to get this working using the server-side methods I discussed here: