aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Add avif images to default known static file MIME types

Open efcoyote opened this issue 3 years ago • 10 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

When developing web applications, the size of images is always a factor. Therefore I decided to use the avif file format. When running my web application (Angular + WebApi) with Kestrel, I have to manually add the MIME type to the FileExtensionContentTypeProvider otherwise the static file isn't served.

Describe the solution you'd like

Please add the extension (.avif) and the MIME type (image/avif) to the dictionary in FileExtensionContentTypeProvider. I can open a PR if wanted.

Additional context

In 2019 the specifications for the avif image format have been released. Meanwhile the format is well supported for example by Chrome, Firefox, Windows, Linux and Android. It is a good candidate for being a successor of jpeg, png and webp also with regard to the open licence.

efcoyote avatar Feb 04 '22 16:02 efcoyote

See previous responses for similar requests:

  • https://github.com/dotnet/aspnetcore/issues/33217#issuecomment-853349203
  • https://github.com/dotnet/aspnetcore/issues/36576#issuecomment-920462795

pranavkm avatar Feb 04 '22 17:02 pranavkm

I saw the comment in the file. I my honest opinion an increasingly widespread image format is more important for web developers than product specific files types like .msg or .dxf.

efcoyote avatar Feb 04 '22 17:02 efcoyote

Triage: we don't think this meets the bar yet for adding by default (especially given that this is the first request we've had for it). You can always add it yourself in your code.

We'd reconsider if there were a lot more demand. Will leave this in Backlog to allow for more comments/upvotes.

adityamandaleeka avatar Feb 07 '22 21:02 adityamandaleeka

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost avatar Feb 07 '22 21:02 ghost

I'd like to add that avif files are significantly smaller than jpg of similar resolution. I switched over to using them to greatly improve my LCP metric with Google to improve my site page rank. Just swapping out a header background jpg with an avif saved me almost 2 seconds of load time on the LCP test for mobile Chrome. This file format should be gaining widespread adoption soon.

I don't think it's a good idea to have devs tear their hair out trying to figure out why an image asset is returning 404 despite having all the file properties set correctly. I didn't even know that an asset in the wwwroot folder or subfolders could return a 404 until I found this issue.

carlin-q-scott avatar Feb 09 '22 22:02 carlin-q-scott

I'm going to disagree here @adityamandaleeka. Windows itself supports it, as does php, android, chrome and edge. We should add it, along with HEIC/HEIF.

The usage of these types is more common than a bunch of the office formats we listed when we inherited the list from IIS, or the now dead silverlight ones :)

blowdart avatar Feb 10 '22 12:02 blowdart

@blowdart - Thank you. Some sanity has returned to this thread. We shouldn't need a choir of developers requesting support for ASP.NET to serve Avif images by default at a time when ALL major browsers support rendering the Avif image format. See https://caniuse.com/avif

Honestly, every time I see Microsoft so late to the party on new industry standards, I question whether I bet my development career on the right company. (shrug) Come on, we can do better than this.

rclabo avatar Dec 15 '23 21:12 rclabo

For others that end up here wondering how to get the static file middleware in .NET 8 (or earlier) to srve avif files, I'll save you a bit of research. This is working for me:

var extensionProvider = new FileExtensionContentTypeProvider();
extensionProvider.Mappings.Add(".avif", "image/avif");
app.UseStaticFiles(new StaticFileOptions {
    ContentTypeProvider = extensionProvider,
    ServeUnknownFileTypes = true
}); 

rclabo avatar Dec 15 '23 21:12 rclabo

Will this ever be considered? https://web.dev/articles/avif-updates-2023

Maybe there should be a more obvious way of configuring what file mappings are used.

amartens181 avatar May 22 '24 21:05 amartens181

@rclabo Answer helped me, but I'm serving up an Angular SPA via IIS alongside a dotnet core API. I had to use:

            app.UseSpaStaticFiles(new StaticFileOptions
            {
                ContentTypeProvider = extensionProvider,
                ServeUnknownFileTypes = true
            });

Took me a bit to come around to the issue being aspnetcore; I had already added the MIME type to IIS.

rmegal avatar Aug 25 '24 19:08 rmegal

Wow, it is a bit disappointing to discover the state of this.

...where we expect them to be applicable to a majority of developers..

This sounds subjective and it is unclear when this ever will happen (who decides how many developers are a majority?). But imho this is also wrong way to look at it.

Support for new static/mime types should be added when it becomes clear a majority browsers are supporting or are going to support these types. You are developing a web server technology. I assume you want the server technology to be up to date, this would include supporting the latest browser trends since that is what the web server technology is being used with.

At least as developer using asp net core (and being happy to use it) I hope you do.

As a side note: a point of discussion would be if you need to wait until most browsers support a new type or if some browsers start to support it. Because it is still the responsibility of the developer using asp net core if they want to use a more exotic (not widely supported) type. It is also only the developer that has to deal with any problems arising from this decision.

JoshaMunnik avatar Sep 02 '24 07:09 JoshaMunnik

I don't have an objection to considering this again. Thanks to everyone who has chimed in on this issue.

adityamandaleeka avatar Sep 03 '24 17:09 adityamandaleeka