8

I can't find a decent answer to this question. I see there are a couple other similar questions that have been asked, but they do not provide me with decent answers.

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

It seems a bit pointless and wasteful to have all the extra white space, comments, and other things on the server. I have looked for different Extensions and NuGet packages, but have been unable to find anything that provides me with a solution.

4 Answers 4

6

You want something like Cassette.

Cassette automatically sorts, concatenates, minifies, caches and versions all your JavaScript, CoffeeScript, CSS, LESS, Sass and HTML templates.

It's very simple to use, just read their documentation. It takes at most 5 minutes to setup.

To install, open the NuGet Package Console and type in:

Install-Package Cassette.Web

This will take care of installing, and setting things up for you.

For help or suggestion, check out their Google Group:

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


There is also the option of using SquishIt. It works fine with MVC3 and serves the same purpose as Cassette. However, personally I prefer Cassette.

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

Sign up to request clarification or add additional context in comments.

Comments

4

Another helpful tool is Chirpy. I used it with VS up to 2010. You are defining bundles with a simple XML file. It integrates into VS so if any file (css, less, js, ...) changes the minified version is automatically (re-)rendered in background.

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

With the following sample file (.chirp.config) the given CSS files are bundled and minified 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>

Comments

1

There is:

Comments

1

I use the WebMarkupMin package on Nuget. It has quite a nice HTML minifier which I use when generating HTML output in my program:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.