Automatically compress html and css when publishing?

I can not find a decent answer to this question. I see that there are several other similar questions that have been asked, but they do not give me decent answers.

In Visual Studio, is there a way to compress all files that should be compressed (HTML, XML, CSS) automatically when publishing the application?

It seems a little pointless and wasteful to have all the extra space, comments, and other things on the server. I searched for various NuGet extensions and packages, but could not find anything that would provide me with a solution.

+7
source share
4 answers

You want something like a cassette .

The cassette automatically sorts, combines, minimizes, caches and versions of all your JavaScript, CoffeeScript, CSS, LESS, Sass, and HTML templates.

It is very easy to use, just read their documentation. It takes no more than 5 minutes to configure.

To install, open the NuGet package console and enter:

Install-Package Cassette.Web 

This will take care of installation and configuration for you.

For help or suggestions, go to your Google group:

http://groups.google.com/group/cassette


There is also the option of using SquishIt. It works great with MVC3 and performs the same task as a cassette. However, I personally prefer the cassette.

http://lostinthegc.wordpress.com/2012/01/14/using-squishit-in-an-asp-net-mvc3-web-application/

+6
source

Another useful tool is Chirpy . I used it from VS until 2010. You define packages using a simple XML file. It integrates into VS, therefore, if any file (css, less, js, ...) changes the mini version, it is automatically (repeatedly) displayed in the background.

http://www.weirdlover.com/2010/05/22/visual-studio-add-in-for-dotless-js-and-css-files/

In the following file example (.chirp.config), these CSS files are inserted and converted into two files named external.min.css and internal.min.css :

 <?xml version="1.0"?> <root> <FileGroup Name="external.css"> <File Path="css/jquery.ui.core.css" /> <File Path="css/jquery.ui.theme.css" /> <File Path="css/jquery.ui.button.css" /> <File Path="css/default.css" /> </FileGroup> <FileGroup Name="internal.css"> <File Path="css/jquery.ui.core.css" /> <File Path="css/jquery.ui.theme.css" /> <File Path="css/jquery.ui.autocomplete.css" /> <File Path="css/jquery.ui.progressbar.css" /> <File Path="css/jquery.ui.accordion.css" /> <File Path="css/default.css" /> <File Path="css/datatables.css" /> </FileGroup> </root> 
+4
source

I am using WebMarkupMin package in Nuget. It has a pretty good HTML minifier that I use when generating HTML output in my program:

 var htmlMinifier = new HtmlMinifier(); var result = htmlMinifier.Minify(myHTML, generateStatistics: false); Console.WriteLine(result.MinifiedContent); 
+1
source

All Articles