I have been trying to use Webp images on my website however they would show up as broken images on all browsers.
I have tried a solution from dejanstojanovic (I didn't completely get what was happening in there, although I did understand it was checking if the browser is compatible with webp and then sending the webp version if it was else it sent a png or jpeg version) however, that didn't work. Similarly, I tried a solution from deanhume but likewise, that too didn't work. Both code returned a webp file which should be supported by chrome however there was a broken image on the page. I checked to make sure it is not the fault of the path by putting a png file and webp file in the same folder and displaying them both. The png file works perfectly, however, the webp file is missing. Furthermore, the webp file also works if I use raw HTML, just not with ASP.NET.
_layout.cshtml
<h5 class="footer-header">Contact Info</h5>
<p class="footer-text">Contact us if you want a custom made dress, or just want to know where your package might be.</p>
<div class="row">
<div class="col-md-1">
<img style="height:50px; width:50px" src="~/Images/LocationPin100h.webp" />
<img style="height:50px; width:50px" src="~/Images/LocationPin100h.png" />
</div>
</div>
web.config in the views folder
<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
<remove name="WebPHandler" />
<add name="WebPHandler" type="Web.Images.WebP.RequestHandler, Web.Images.WebP" path="*.webp" verb="GET" />
</handlers>
<staticContent>
<mimeMap fileExtension=".webp" mimeType="image/webp" />
</staticContent>
</system.webServer>
how it looks on the page: https://ibb.co/QjJkqv7
According to caniuse, currently 79.2% of browsers support the WebP image format. That would include Chrome, Firefox, and Edge. Safari will support WebP in version 14, which is expected to be released in September 2020.
WebP is no longer a new wave image file format. It's supported by all five of the top mobile browsers including Chrome Mobile, Mobile Safari, Chromium, Samsung Browser, Facebook on Android, and more.
Once you've activated the plugin, you can use the General Settings box to choose your compression level. To enable WebP images, scroll down to the Optimization section and find the WebP Format section: Check the box to Create webp versions of images. Check the box to Display images in webp format…
I have figured it out. There are two Web.config files. One located in the project root folder and one located in the views folder. I had to add:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".webp" mimeType="image/webp" />
</staticContent>
</system.webServer>
into the web.config file located in the root folder, not the one located in the views folder as I was previously doing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With