All Projects → tompazourek → RazorHtmlMinifier.Mvc5

tompazourek / RazorHtmlMinifier.Mvc5

Licence: MIT license
↘️ Trivial compile-time Razor HTML Minifier for ASP.NET MVC 5.

Programming Languages

C#
18002 projects
HTML
75241 projects
ASP.NET
160 projects

Projects that are alternatives of or similar to RazorHtmlMinifier.Mvc5

MinifyAll
A 𝗩𝗦𝗖𝗼𝗱𝗲 𝗺𝗶𝗻𝗶𝗳𝗶𝗲𝗿 for JS, JSON/C, CSS, and HTML, you will love its simplicity! 🌟 𝘾𝙤𝙢𝙥𝙧𝙚𝙨𝙨 and 𝙜𝙯𝙞𝙥 files and folders 📦 Reduce your bundle and file sizes with lightning speed ⚡
Stars: ✭ 54 (+74.19%)
Mutual labels:  minification, minifier
laravel-minify-html
Very, very simple HTML minifier with Laravel support
Stars: ✭ 14 (-54.84%)
Mutual labels:  html-minifier, minifier
DNZ.SEOChecker
SEO Checker and Recommander Plugin (like wordpress Yoast) for ASP.NET Core.
Stars: ✭ 18 (-41.94%)
Mutual labels:  asp-net, asp-net-mvc
BlipBinding
ASP.NET MVC case study solution for PluralSight Guides. Demonstrates how to use default MVC model binding with hierarchical form data.
Stars: ✭ 29 (-6.45%)
Mutual labels:  asp-net, asp-net-mvc
AspNetCore-Dynamic-Permission
Dynamic Permission Samples in ASP.NET Core and ASP.NET MVC 5.
Stars: ✭ 19 (-38.71%)
Mutual labels:  asp-net, asp-net-mvc
FlexDotnetCMS
A powerful, flexible, decoupled and easy to use and Fully Featured ASP .NET CMS, it can also be used as a Headless CMS
Stars: ✭ 45 (+45.16%)
Mutual labels:  asp-net, razor
Uintra
A flexible and lightweight Umbraco based framework, for making an Intranet, Extranet or social platform based on known conventions.
Stars: ✭ 43 (+38.71%)
Mutual labels:  asp-net, asp-net-mvc
Svgo
⚙️ Node.js tool for optimizing SVG files
Stars: ✭ 17,050 (+54900%)
Mutual labels:  optimization, minification
MinifyAllCli
📦 A lightweight, simple and easy npm tool to 𝗺𝗶𝗻𝗶𝗳𝘆 JSON/C, HTML and CSS! Also known as MinifyAll core! ⭐ Usable as 𝑪𝑳𝑰 tool or 𝒊𝒎𝒑𝒐𝒓𝒕𝒂𝒃𝒍𝒆 in TS/JS as a 𝑴𝑶𝑫𝑼𝑳𝑬 🥰
Stars: ✭ 21 (-32.26%)
Mutual labels:  minification, minifier
TraceHub
Centralized and distributed logging for Web applications and services, extending System.Diagnostics and Essential.Diagnostics, providing structured tracing and logging withou needing to change 1 line of your application codes
Stars: ✭ 22 (-29.03%)
Mutual labels:  asp-net, asp-net-mvc
Esbuild Loader
⚡️ Speed up your Webpack build with esbuild
Stars: ✭ 1,245 (+3916.13%)
Mutual labels:  optimization, minification
Awesome-Nuget-Packages
📦 A collection of awesome and top .NET packages sorted by most popular needs.
Stars: ✭ 87 (+180.65%)
Mutual labels:  asp-net, asp-net-mvc
Clean Css
Fast and efficient CSS optimizer for node.js and the Web
Stars: ✭ 3,863 (+12361.29%)
Mutual labels:  optimization, minification
ByteScout-SDK-SourceCode
ALL source code samples for ByteScout SDKs and Web API API products.
Stars: ✭ 24 (-22.58%)
Mutual labels:  asp-net, asp-net-mvc
Statically
⚡️ The best free and fast CDN for images, CSS, JavaScript, and open source.
Stars: ✭ 299 (+864.52%)
Mutual labels:  optimization, minification
PersianDataAnnotations
PersianDataAnnotations is ASP.NET Core MVC & ASP.NET MVC Custom Localization DataAnnotations (Localized MVC Errors) for Persian(Farsi) language - فارسی سازی خطاهای اعتبارسنجی توکار ام.وی.سی. و کور.ام.وی.سی. برای نمایش اعتبار سنجی سمت کلاینت
Stars: ✭ 38 (+22.58%)
Mutual labels:  asp-net, asp-net-mvc
Dasblog Core
The original DasBlog reimagined with ASP.NET Core
Stars: ✭ 252 (+712.9%)
Mutual labels:  asp-net, razor
imagemin-power-cli
Optimize (compress) images with power using imagemin 💪
Stars: ✭ 13 (-58.06%)
Mutual labels:  minification, minifier
elmah.io
ELMAH error logger for sending errors to elmah.io.
Stars: ✭ 31 (+0%)
Mutual labels:  asp-net, asp-net-mvc
Cake-Shop
A sample Cake Shop Website built with ASP.NET Core (Multi-Page Application)
Stars: ✭ 44 (+41.94%)
Mutual labels:  asp-net, asp-net-mvc

RazorHtmlMinifier.Mvc5 logo RazorHtmlMinifier.Mvc5

Build status NuGet version NuGet downloads

Trivial compile-time Razor HTML Minifier for ASP.NET MVC 5.

Installation

Download

Binaries of the last build can be downloaded on the AppVeyor CI page of the project.

The library is also published on NuGet.org, install using:

PM> Install-Package RazorHtmlMinifier.Mvc5

RazorHtmlMinifier.Mvc5 is built for .NET v4.8 with a dependency on ASP.NET MVC 5.2.9 and System.Web.

Configuration

Find the Web.config with your Razor configuration (by default it's in Views/Web.config). You should see something like this inside:

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.9.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

In order to start minifying views and partial views, replace it with (after the NuGet package is installed):

<host factoryType="RazorHtmlMinifier.Mvc5.MinifyingMvcWebRazorHostFactory, RazorHtmlMinifier.Mvc5, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a517a17e203fcde4" />

Then rebuild your solution, which should also restart the app.

If you're using Razor @helper functions placed inside the App_Code folder, you have to do additional configuration in order to minify those. In the root Web.config, you should see something like this:

<compilation debug="true" targetFramework="4.8" />

Your <compilation> element might have different attributes. Leave the current attributes as-is, and add <buildProviders> like so:

<compilation debug="true" targetFramework="4.8">
    <buildProviders>
        <add extension=".cshtml" type="RazorHtmlMinifier.Mvc5.MinifyingRazorBuildProvider, RazorHtmlMinifier.Mvc5" />
    </buildProviders>
</compilation>

How it works

The minifier processes the code generated during Razor compilation. Because it runs in compile-time, it shouldn't add any overhead during runtime.

The entire source code is just two files, feel free to view them.

The minification algorithm is fairly trivial. It basically:

  • replaces any amount of whitespace characters with a single space;
  • replaces any line breaks with just the line feed character (\n);
  • if there's a sequence of whitespace characters and line breaks, it only takes the first in the sequence.

The minification process is deliberately trivial so that it would be easy to understand and expect.

CAUTION! The minification is not context-sensitive, and it doesn't have any special handling of <pre> tags or similar. If you use <pre> tags or have any other significant white-space in your HTML, you shouldn't use this library.

The code is inspired by Meleze.Web (an older project), but it's much simplified and updated to be used for with the latest version of ASP.NET MVC.

Resolving IntelliSense issues

When you change the Razor factory, you might experience IntelliSense issues in Visual Studio.

I've investigated this and it looks like VS actually needs to have the assembly in GAC for IntelliSense to work. Luckily, now when the latest version of the library is strong-named, it's possible to add it to GAC. Adding the assembly to GAC shouldn't have any side-effects, but it will need to be added on every developer machine that wants to use see the IntelliSense in Razor files completely (without the squiggly undelines), which can be a hassle.

If you want to add the assembly to GAC, you'll need to do the following:

  • Open Developer Command Prompt for VS (you'll find it in Start menu) as an Administrator.
  • Navigate to the folder of the NuGet package: cd "C:\PATH_TO_YOUR_SOLUTION\packages\RazorHtmlMinifier.Mvc5.2.0.0\lib\net45"
  • Install it to GAC: gacutil /i RazorHtmlMinifier.Mvc5.dll (it should respond Assembly successfully added to the cache)
  • Restart Visual Studio (and maybe also clear any ReSharper caches if you're using that)

Then it should start working.

There are also other alternative solutions:

  • Set up the host factory in Web.config.Release instead of Web.config. That will make the minification run only when the Release configs are applied, and while debugging, you can keep the original host factory, which doesn't have problems with intellisense.
  • Set the host factory in the Web.config file in runtime, e.g. in Global.asax. You'd have to use the WebConfigurationManager API to modify the Web.config during runtime.

However, I wouldn't recommend either of those (I also haven't tried them), as they feel more like a hack, and might cause more issues if you'd be doing stuff like precompilation of the views. Adding the assembly to GAC is probably the easiest, it's still annoying that VS requires that though...

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].