-
Notifications
You must be signed in to change notification settings - Fork 221
Building Razor views in release mode should minify HTML #423
Comments
Hey @RehanSaeed are you suggesting to add Razor minification to the Visual Studio project templates? |
In my head I imagine minification of cshtml being just a check-box in the project properties. It could then be turned off for Debug/Development and on for Release/Staging/Production builds. Adding this to the project as indicated in the blog is just one way of achieving this. I'm sure there are other ways which may be more integrated. The benefits of minifying HTML are clearly shown by Mads Kristensen in his blog article. The best way of achieving minification is not during runtime as many frameworks do but during compile time where there is no performance hit to the application. Because of this fact, only Microsoft can reliably provide proper tooling to allow for this feature. What are your thoughts? |
Typically all minification occurs (in asp.net 5) via third party components that are configured to run post-build/restore etc. In my mind a .cshtml minifier would fall under the same bubble. With that mindset, if we were to add default .cshtml minification it would exist at the project template level. |
It seems then that the solution employed by Dean Hume in his blog article is very close to what you are suggesting. This would be a very cool feature if implemented. Most developers will not go to the added trouble of adding this feature themselves. It would probably save terabytes of bandwidth when you add up how many developers use ASP.NET MVC 6 and start using this feature because it comes right out of the box. |
@RehanSaeed thanks for the suggestion. Will discuss this with others to see if it has a place in our templates 😄 |
Excellent. Thank You! |
I completely disagree with the suggested implementation. Why not do this as part of pre-compilation? It can be an option in the I think that this issue should be re-opened. /cc @guardrex |
@glen-84 👍 I hate what I'm doing now, so that would be great. However, @NTaylorMullen has there been any discussion on giving Razor directives line termination characters so that they wouldn't need to be on individual lines at the top of the markup and the Razor parser can grab them from minified markup? That's my main pain point with using Gulp to minify Razor views. |
@guardrex no there hasn't. Not a horrible idea however, open an issue and we can discuss 😄 |
I wrote a blog post about how much bandwidth this feature might have saved the internet here. |
May I know what's the status for this suggestion, is it denied? Suggestion by @glen-84 to have a precompiled minification would be really great. Scenario: I have templates which I bought containing lots of HTML and Javascript comments. I want to leave it in .cshtml because it helps during development, but I don't want / need those comments to appear in production. On-the-fly minification during runtime can be done, but since the HTML and Javascript portions in a .cshtml is pretty much static most of the time, it would be great if those static portions can be minified during precompilation and avoid unnecessary performance penalty for just-in-time runtime minification. |
@ShamsulAmry Backlogged at #444 |
Just wanted to throw in my support for built-in minification either at compile time or run-time. |
Shouldn't this reopen? I know for sure that knockout has a measurable performance increase (1 second boost in a real world project I have been working on) from html minification. It's because when you have a:
The dom has Minified:
When minified it only sees I'm using WebMarkupMin but this is done at runtime which impacts performance on a high load site. Would be nice if this could be done when the razor views get built. Would also be good with an option to do it in debug mode as well as release. |
Thanks. Forgot to say we're still using asp.net 4 and mvc 5 for new projects. I'm guessing we should upgrade. |
For anybody interested in this, I built a tiny HTML minifier that can be used with MVC 5: |
@guardrex Your minifier is cool, and I'm using it (thanks!), but is there no way to do this as compile-time? Your minifier works "during compile-time during runtime" if I understand correctly - because it's part of the pipeline. But if you're doing a bin deploy, surely this minification should be specified in the |
@lonix1 I'm glad to hear it still works. lol ... I haven't looked at this subject for quite a while now. That code replaces the Razor Template Engine. Since it should run with view precompilation, it should be working at compile time. There was a time when precomp only worked for framework-dependent deployments, but AFAIK they fixed that. aspnet/MvcPrecompilation#102 It wouldn't be specified in the project file because that code interacts with the Razor build engine (as a replacement of the Razor Template Engine). It's a service registration to replace the OOB engine ... .ConfigureServices(services =>
{
services.AddMvc();
services.AddSingleton<RazorTemplateEngine, CustomRazorTemplateEngine>();
}) |
Is this feature available on ASP Core 2.1 or you have denied it ? |
Minifying HTML is difficult in ASP.NET MVC. Comments and white space in .cshtml files could be removed when building in release mode.
This project allows the minification of your .cshtml files using a post build event. This should be built into the tooling and not a separate product.
The text was updated successfully, but these errors were encountered: