|
1 | 1 | RazorHtmlMinifier.Mvc5
|
2 | 2 | ======================
|
3 | 3 |
|
4 |
| -*Razor HTML Minifier for ASP.NET MVC 5* |
| 4 | +[](https://ci.appveyor.com/project/tompazourek/razorhtmlminifier-mvc5) |
5 | 5 |
|
6 |
| -TODO |
| 6 | +*Trivial compile-time Razor HTML Minifier for ASP.NET MVC 5.* |
| 7 | + |
| 8 | +Installation |
| 9 | +------------ |
| 10 | + |
| 11 | +### Download |
| 12 | + |
| 13 | +Binaries of the last build can be downloaded on the [AppVeyor CI page of the project](https://ci.appveyor.com/project/tompazourek/razorhtmlminifier-mvc5/build/artifacts). |
| 14 | + |
| 15 | +The library is also [published on NuGet.org](https://www.nuget.org/packages/RazorHtmlMinifier.Mvc5/), install using: |
| 16 | + |
| 17 | +``` |
| 18 | +PM> Install-Package RazorHtmlMinifier.Mvc5 |
| 19 | +``` |
| 20 | + |
| 21 | +<sup>RazorHtmlMinifier.Mvc5 is is built as for .NET v4.5 with a dependency on ASP.NET MVC 5.2.3.</sup> |
| 22 | + |
| 23 | +### Configuration |
| 24 | + |
| 25 | +Find the **Web.config** with your Razor configuration (by default it's in `Views/Web.config`). You should see something like this inside: |
| 26 | + |
| 27 | +```xml |
| 28 | +<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> |
| 29 | +``` |
| 30 | + |
| 31 | +In order to start minifying, replace it with (after the NuGet package is installed): |
| 32 | + |
| 33 | +```xml |
| 34 | +<host factoryType="RazorHtmlMinifier.Mvc5.MinifyingMvcWebRazorHostFactory, RazorHtmlMinifier.Mvc5, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> |
| 35 | +``` |
| 36 | + |
| 37 | +Then rebuild your solution, which should also restart the app. |
| 38 | + |
| 39 | + |
| 40 | +How it works |
| 41 | +------------ |
| 42 | + |
| 43 | +The minifier processes the code generated during Razor compilation. Because it runs in compile-time, it shouldn't add any overhead during runtime. |
| 44 | + |
| 45 | +The entire source code is just a [single file](https://github.com/tompazourek/RazorHtmlMinifier.Mvc5/blob/master/src/RazorHtmlMinifier.Mvc5/MinifyingMvcWebRazorHostFactory.cs), feel free to view it. |
| 46 | + |
| 47 | +The minification applied is very trivial as you can [see here](https://github.com/tompazourek/RazorHtmlMinifier.Mvc5/blob/master/src/RazorHtmlMinifier.Mvc5/MinifyingMvcWebRazorHostFactory.cs#L47-L55). It basically: |
| 48 | + |
| 49 | +- replaces multiple white-space characters next to each other with a single space; |
| 50 | +- replaces multiple white-space characters containing line breaks with a single line break. |
| 51 | + |
| 52 | +The minification process is deliberately trivial so that its behaviour would be easy to understand and expect. |
| 53 | + |
| 54 | +**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.** |
| 55 | + |
| 56 | +The code is inspired by [Meleze.Web](https://github.com/meleze/Meleze.Web) (an older project), but it's much simplified and updated to be used for with the latest version of ASP.NET MVC. |
0 commit comments