Crushing PNGs in .NET

Updated on Thursday, May 13, 2021

Crushing PNGs in .NET

I'm working on page speed and Google PageSpeed Insights is telling me that my PNGs are just way too large. Sadly .NET does not provide any way to optimize PNG images so there is no easy fix - just unmanaged libraries and command line tools.

I have an allergy to manual processes so I've lashed up some code to automatically find and optimize PNGs in my App_Data folder using PNGCRUSH. I can call CrushAllImages() to fix up everything or CrushImage() when I need to fix up a specific PNG. Code below:

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Crushing PNGs in .NET #code #png #compression #crush #asp.net #mvc How to automatically reduce the size of PNG images for a .NET website using PNGCRUSH. )

Minify and inline CSS for ASP.NET MVC

Updated on Wednesday, April 28, 2021

Minify and inline CSS for ASP.NET MVC

ASP.NET has a CssMinify class (and a JavaScript variant as well) designed for use in the bundling pipeline. But what if you want to have your CSS minified and inline? Here is an action that is working for me (rendered into a style tag on my _Layout.cshtml using @Html.Action("InlineCss", "Home")).

Note that I'm using this to inline CSS for this blog. The pages are cached so I'm not worried about how well this action performs. My blog is also basically all landing pages so I'm also not worried about caching a non-inline version for later use, I just drop all the CSS on every page.

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Minify and inline CSS for ASP.NET MVC #code #asp.net #mvc #css #inline #minify How to use ASP.NET MVC bundles to inline CSS and JavaScript for high performing landing pages. )