dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.2k stars 9.94k forks source link

Add avif images to default known static file MIME types #39984

Open efcoyote opened 2 years ago

efcoyote commented 2 years ago

Is there an existing issue for this?

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.

pranavkm commented 2 years ago

See previous responses for similar requests:

efcoyote commented 2 years ago

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.

adityamandaleeka commented 2 years ago

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.

ghost commented 2 years ago

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.

carlin-q-scott commented 2 years ago

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.

blowdart commented 2 years ago

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 :)

rclabo commented 9 months ago

@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 commented 9 months ago

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
}); 
amartens181 commented 3 months ago

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.

rmegal commented 3 weeks ago

@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.

JoshaMunnik commented 2 weeks ago

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.

adityamandaleeka commented 1 week ago

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