Minification, bundling and compiling sample
C# JavaScript CSS
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/minicompiler
.gitignore
LICENSE.md
README.md
minicompiler.sln

README.md

Minifying, Bundling and Compressing in ASP.NET Core

This repository contains a working sample of how to achieve LESS/SASS pre-processing, Minification, Bundling and GZip Compression of static files on Web Applications running ASP.NET Core (either Full Framework or .Net Core Apps) by using Visual Studio 2015 Extensions as an alternative to NPM+Gulp tasks.

This project uses Mads Kristensen's Bundler & Minifier Extension for bundling and Web Compiler for SASS/LESS pre-processing.

Client libraries are resolved with Bower.

SASS/LESS pre-processing is achieved by using compilerconfig.json. Minification, Bundling and Gzip Compression is achieved by using bundleconfig.json

Both Extensions have their code available on GitHub:

GZip pipeline processing is achieved using a Middleware in Startup.cs:

app.UseStaticFiles(new StaticFileOptions()
        {
            OnPrepareResponse = (context) =>
            {
                if ("application/x-gzip".Equals(context.Context.Response.Headers["Content-Type"]))
                {
                    if (context.File.Name.EndsWith("js.gz"))
                    {
                        context.Context.Response.Headers["Content-Type"] = "application/javascript";
                    }
                    else if (context.File.Name.EndsWith("css.gz"))
                    {
                        context.Context.Response.Headers["Content-Type"] = "text/css";
                    }
                    context.Context.Response.Headers.Add("Content-Encoding", "gzip");
                }
                context.Context.Response.Headers.Add("Cache-Control", "public, max-age=2592000");
            }
        });