Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC 4 Minification & Background Images

I'm currently using ASP.NET MVC 4 CSS/JavaScript Optimizer. It works good with my own CSS/JavaScript, but I also want to use it with plugins. Each plugin has its own folder:

~/Content/css // my own css, ok
~/Content/plugins/rateit
~/Content/plugins/chosen
~/Content/plugins/...

I can add this files to optimizer:

var bundle = new Bundle("~/Content/opt", new CssMinify());
...
bundle.AddFile("~/Content/plugins/chosen/chosen.css", "*.css");
BundleTable.Bundles.Add(bundle);

But in this case, after optimization, css is in another folder and browser cannot find background images anymore. Is there any solution to automatically modify css path for background images?

I can copy all plugins in one folder, but with a lot of plugins, it's not a good idea.

like image 384
user1224129 Avatar asked Mar 20 '12 01:03

user1224129


People also ask

What is minification in ASP NET MVC?

MVC implements a process called minification on the bundled files. Minification removes all whitespace and renames variables to their shortest possible name, thereby removing all excess characters (and thereby excess file size) from the bundle. Because the file is smaller, it takes less time to download.

How can we achieve minification in MVC?

Bundling and minification can be enabled or disabled in two ways: either setting the value of the debug attribute in the compilation Element in the Web. config file or setting the enableOptimizations property on the BundleTable class. In the following example, debug is set to true in web.

What is bundling and minification in ASP NET MVC?

Bundling is one of the features of MVC. By implementing this, we can improve performance request load time. Minification is the process of removing unnecessary data without changing its functionality such as removing white spaces, comments, converting the large variable names to small, etc.

What is minification C#?

What is minification. Minification is a = process of removing unnecessary comments, spaces from JavaScript / css file. Main intention of minification is to decrease the size of javascript / css files so that load time will get decreased. Functionality of javacript / css file remains same in minification.


1 Answers

Might have a look at RequestReduce. It's another .net based minifier/bundler and it will rewrite all urls in the minified/bundled css to be absolute. This includes fonts and background images. It will also automatically expand any imports in the css. Additionally, where it thinks it can, it will sprite the background images.

like image 76
Matt Wrock Avatar answered Sep 22 '22 13:09

Matt Wrock