31 points · by bobblywobbles · 8y ago · 64 comments
1. Add package called `WebMarkupMin.AspNetCore2`.
2. Add and configure code in your `Startup.cs` like so.
services.AddWebMarkupMin(
options =>
{
options.AllowMinificationInDevelopmentEnvironment = true;
options.AllowCompressionInDevelopmentEnvironment = true;
options.DisablePoweredByHttpHeaders = true;
})
.AddHtmlMinification(
options =>
{
options.MinificationSettings.RemoveRedundantAttributes = true;
options.MinificationSettings.RemoveHttpProtocolFromAttributes = true;
options.MinificationSettings.RemoveHttpsProtocolFromAttributes = true;
// More options if you like so
})
.AddHttpCompression();
Not only will this minfy HTML output, but also apply a lot more optimisations based on your configuration.The main difference between this and WebMarkupMin is that WebMarkupMin runs at runtime - therefore it is costing time to minify when you can already minify the files before launching your web application.
Also, this reduces complexity of the project. Both methods are fine, it's just I prefer this one.
To illustrate the point, let's take the current Hacker News front page:
+=================+========+
| Description | Bytes |
+=================+========+
| Original | 43,595 |
+-----------------+--------+
| Minified | 41,368 |
+-----------------+--------+
| Original (GZIP) | 7,350 |
+-----------------+--------+
| Minified (GZIP) | 7,247 |
+-----------------+--------+
You've saved 103 bytes, or ~1.4%.Was there a specific case you were referring to?
I mean, it's a cheap shot, but it's frankly so unproductive compared to Django it's basically a running joke. Not that .net core doesn't see a lot of usage, much like angular it's very popular in the european public sector, but it's just such a waste of resources. By resources I mean, man hours by the way, because it's really effective technically, it's just that, all that you can pay for around a million years of AWS/Azure time for the extra wage-hours you need to pay programmers when you use .net instead of something useful.
And in two years it'll be obsolete anyway, because by then Microsoft will have completely changed their direction, again. I say this, as as someone who's running Azure and 365 as our cloud provider for the majority of our services, as someone who's genuinely happy with the services Microsoft provides and having had a great 25 year long business relationship with them, but as far as development goes, .net is just too crazy to be worth it these years.
I also find it preposterous that .NET Core will be obsolete in 2 years, and I'm not sure what you mean about Microsoft changing direction "again" - the .NET Framework was released almost 2 decades ago, and I find the recent move to a cross-platform runtime to make for exciting times!
I mean, even .net standard came and went before we even started using it, considering it won't be part of .net core 3.0.
You could say the same about the whole industry, also I don't think "obsolete" is a good term, maybe some technologies are not the "new shining thing" out there, but well written systems with "old" and "uncool" technologies are still working perfectly fine and they will keep working fine in the future.
I feel .net core is productive to django, but I don't like using python so my opinion is bias.
Django is at a completely different abstraction layer.
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.
And yes, I am the author.
https://www.softfluent.com/blog/dev/Enabling-gzip-compressio...
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%).
Vue is probably the best general-purpose SPA frontend option for .NET right now, in my opinion, but I'm really hoping that Blazor unseats it. Being able to reuse library code in the frontend would be fantastic! I've got a few use cases for this already that would avoid round trips to the server or duplicating/maintaining logic in different languages.
Very few websites are actually worthwhile doing as SPA, and guess what they are actually fast to deliver static content instead of JS frameworks.
If you're still using Razorscript then you're probably causing more work for yourself than you realize, both from a resourcing standpoint and a functional one.
Server-side rendering is my default go-to - IMO, this works very well for the majority of needs.
I only bust out a front-end framework if the app is sufficiently complex that it can justify the extra work.
Maybe your app is that simple, and maybe moving a lot of it to JS/AJAX would make it more complicated and less accessible to the end user.
They're super fast (HN is a good example!), and dev work is much quicker for basic stuff that doesn't involve too much complex interaction.
If you're using Razorscript still you are doing yourself and your company a large disservice. There isn't anything Razorscript brings to the table that makes it a worthwhile option. And even worse, if you are using Razorscript, you will have to write more code to specifically be in harmony with any other kind of front end framework.
And please I beg of anyone replying to these messages to not get confused and assume that pages not written in Razorscript are somehow specifically trying to be an SPA. They are not. The clear difference between something like Razorscript and say using server rendered react, is that the former will only ever be rendered on the server, and the latter can be rendered on both the server and the client.
Thanks !