Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC ASP.NET minify Views .cshtml

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?
like image 440
theLaw Avatar asked Mar 04 '14 14:03

theLaw


People also ask

How do you minify Cshtml?

To minify the CSHTML file, we will use WebMarkupMin.

How does bundling increase performance in MVC?

Bundling and minification are two techniques you can use in ASP.NET 4.5 to improve request load time. Bundling and minification improves load time by reducing the number of requests to the server and reducing the size of requested assets (such as CSS and JavaScript.)

What is difference between bundling and minification?

Bundling and minification are two techniques you can use in ASP.NET to improve page load performance for your web application. Bundling combines multiple files into a single file. Minification performs a variety of different code optimizations to scripts and CSS, which results in smaller payloads.

How do you use bundling and minification in MVC 5?

Bundling and minification can be enabled or disabled in two ways: either setting the value of the debug attribute in the compilation Element in the Web. config file or setting the enableOptimizations property on the BundleTable class. In the following example, debug is set to true in web.


2 Answers

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).

like image 67
Tom Pažourek Avatar answered Nov 04 '22 09:11

Tom Pažourek


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

https://github.com/jitbit/HtmlOptimizerMvc4

like image 27
Alex from Jitbit Avatar answered Nov 04 '22 08:11

Alex from Jitbit