4 ms·
Neat, but I thought the view compilations were cached and optimized already? Wouldn't it be better to add a pipeline that minifies the compiled views instead of
by Novashi 8y ago
Neat, but I thought the view compilations were cached and optimized already? Wouldn't it be better to add a pipeline that minifies the compiled views instead of having files on disk?
- c0nfused 8y agoThat does appear to be an option and one I would persue as well: https://www.softfluent.com/blog/dev/Enabling-gzip-compression-with-ASP-NET-Core https://www.softfluent.com/blog/dev/Enabling-gzip-compressio...
- bobblywobbles 8y agoGzip compression is good, but if you can also have your files minified it does provide more performance gains (even if marginal). If you have to set up minification once to gain ~3% reduction in page size, I think we would all do it (even though its 3%).
- sebazzz 8y agoI also think it is better to override the View Engine to allow the minified files to take precedence. Nevertheless I doubt that minification of the html is very useful unless you're Google. With cutting away dependencies and a good lazy loading strategy you can achieve a lot more.
- bobblywobbles 8y agoThe savings is marginal, but why not configure your solution to save extra bytes then forget it is even there?
- sebazzz 8y agoWhy? Because software is complex enough as it is, and you need to question whether you need to add additional moving parts for little benefit. Everything that you can add, can fail in some reason. Especially something like HTML minification, which cannot be transparently minified (for instance, when you need to use white-space: pre)
- bobblywobbles 8y agoI believe the following project does exactly that: WebMarkupMin.AspNetCore2. The one consideration to this project is that the minifications are done at runtime. Doing the minification before the application starts saves time from a pipeline minifying on the fly.
- zamalek 8y agoThe easiest hypothetical option would be to instruct the .cshtml code generator to ignore insignificant whitespace, but I don't think it currently supports that.
- bobblywobbles 8y agoWebMarkupMin doesn't support that?
- zamalek 8y agoI think it does post-processing on the HTML once it has been generated. ASP.Net works by generating an assembly from source files (like .cshtml) that essentially amounts to a whole bunch of `Response.Write("<HTML>")`. If it (Razor in this case) could be made aware of insignificant whitespace, it could omit the writes for whitespace.
- Novashi 8y ago>Doing the minification before the application starts saves time from a pipeline minifying on the fly. That would only affect a cold-start (app pool recycle) or a view recompile before that'd be an performance concern, unless I don't understand how/when views are cached and then evicted from cache. If you have a lot of views with a lot of partial views inside them, then yeah, you'd only want to run minification once on the final view, instead of for every partial view. I'm not sure if you'd have (or want) that much control over the view rendering process. Btw it's a cool post if you're the author.
- bobblywobbles 8y ago