Reputation: 1291
I have two simple questions:
.cshtml
file like a JavaScript file or a CSS file?Upvotes: 8
Views: 10863
Reputation: 9429
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
Upvotes: 1
Reputation: 10167
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).
Upvotes: 4
Reputation: 60566
This tool is a Razor compiler that minified HTML at precomile-time:
https://github.com/jitbit/HtmlOptimizerMvc4
Upvotes: 1