I have two simple questions:

  1. Is there a way to minify a .cshtml file like a JavaScript file or a CSS file?
  2. Are there any performance improvements if we minify all the views in a project?
有帮助吗?

解决方案 2

This tool is a Razor compiler that minified HTML at precomile-time:

https://github.com/jitbit/HtmlOptimizerMvc4

其他提示

For anybody interested in this, I built a simple HTML minification library that can be used with MVC 5:

https://github.com/tompazourek/RazorHtmlMinifier.Mvc5

It operates in compile-time instead of runtime, so it doesn't add any performance overhead. The minification is very simple (just replaces lots of spaces with one space).

There are many libraries to do such a thing. To answer your question, I have created a setup/process where your .cshtml files can be minified by a task runner within Visual Studio. The post itself describes this using .NET Core, but it is easily transferable over to .NET Framework if need be.

The benefits of this approach, versus other libraries, is I take additional steps to minify the .cshtml to further reduce size and improve performance.

https://debugandrelease.blogspot.com/2018/11/automatically-minifying-cshtml-files-in.html

The core library that does the minification is hosted in NPM: https://www.npmjs.com/package/gulp-cshtml-minify

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top