Ben
Ben

Reputation: 609

ASP.NET compress image

I have an image handler which serves jpegs from disk to the browser, like this:

_context.Response.ContentType = "image/jpeg";
_context.Response.TransmitFile(filepath);

Trying to follow Googles pagespeed recommendations and it's advising me to losslessly compress these images.

Is there a way I can do that within this handler before serving them. There are a few hundred thousand so optimising them individually wouldn't really be an option.

Thanks

Upvotes: 1

Views: 984

Answers (1)

wertzui
wertzui

Reputation: 5750

Put this into your Web.config to enable compression

<system.webServer>
  <urlCompression doStaticCompression="true" doDynamicCompression="true" />
</system.webServer>

However mind that dynamic compression has a performance hit, so do your benchmarking first ;)

Upvotes: 1

Related Questions