An open API service indexing awesome lists of open source software.

https://github.com/omaxel/rcompressor

A compressor for Razor Views.
https://github.com/omaxel/rcompressor

aspnet-core-mvc aspnet-mvc compressor optimization optimization-tools razor razor-views

Last synced: 8 months ago
JSON representation

A compressor for Razor Views.

Awesome Lists containing this project

README

          

RCompressor

# RCompressor

A compressor for Razor Views.

**Help me!** Improve this translation with a pull request.

### [Download latest version](https://github.com/OmarMuscatello/RCompressor/releases/download/v1.0/RCompressor-v1.0.zip)
or see [previous versions](https://github.com/OmarMuscatello/RCompressor/releases).

##### Summary
- [Introduction](#introduction)
- [How to use](#how-to-use)
- [Command line usage](#command-line-usage)

## Introduction
Have you ever thought that the generated HTML from a `.cshtml` file is not optimized?

Take a look at the below code which is the content of a simple `_Layout.cshtml` file:

```



@ViewData["Title"] - WebApplication6


@RenderBody()
MyWebApplication

@RenderSection("Scripts", required: false)

```

And the below code is the content of a simple `Index.cshtml` file:

```
@{
ViewData["Title"] = "Home Page";
}


This the Index page



```

When you visit the page through the browser, the generated HTML is:

```



Home Page - WebApplication6



This the Index page



MyWebApplication

```

How many spaces and empty new lines!

The response size is 650B. This is not a problem if the page is small, but think about bigger pages.

Using **RCompressor**, you can strip out the code from spaces, empty lines, and comments.

Processing the previous `.cshtml` files with **RCompressor** the response size becomes 604B, which is ~8% smaller. You can save a lot of bytes in bigger files.

## How to use
- [Download](https://github.com/OmarMuscatello/RCompressor/releases/download/v1.0/RCompressor-v1.0.zip) the latest version of **RCompressor** and launch it (no installation required);
- paste the directory/file path in the first field;
- check the *Scan subfolders* option if required;
- press the *Compress* button.

### Command line usage
You can use **RCompressor** using the command line by passing the paths as parameters.

Add the `-subfolders` option to scan subfolders.

**Usage example:**
```
> RCompressor.exe -subfolders "C:\MyDir" "C:\MyFile.cshtml"
```

**RCompressor** will compress all `.cshtml` files inside `C:\MyDir` and subfolders. It will also compress the `C:\MyFile.cshtml` file.