ASP.NET MVC Verify if Minification of CSS is Working Properly or Not?

In this article we are discussing how to verify minification of CSS is working or not in Asp.Net MVC.

First of all, what is Minification in Asp.Net?

Minification is the technique you can use in ASP.NET to improve request load time. Minification improves loading time by reducing the number of requests to the server. Hence it reducing the size of requested CSS and JavaScripts.

Minification performs a lot of different coding optimizations to CSS, such as removing unnecessary white space, comments and shortening variable names to one character.

Now, Our main issue is How to verify if minification of CSS bundling is working properly or not.

To do this, you need to view page source and find out Link tag for CSS bundle.

Example:

First of all, you have to open that CSS bundle URL.

Now, just look in your browser’s address bar.

resolve_asp.net_css_bundling_problem

When you open source code please notice that you can see that all CSS files are bundled in one single URL but on header part of page you will see some errors which restricts minification. Find below list of errors which generally occurs on CSS minification in asp.net mvc.

/* Minification failed. Returning unminified contents.
(17483,98): run-time error CSS1034: Expected closing parenthesis, found ‘,’
(17483,98): run-time error CSS1042: Expected function, found ‘,’
(17483,137): run-time error CSS1062: Expected semicolon or closing curly-brace, found ‘)’
(17484,63): run-time error CSS1034: Expected closing parenthesis, found ‘,’
(17484,63): run-time error CSS1042: Expected function, found ‘,’
(17484,92): run-time error CSS1062: Expected semicolon or closing curly-brace, found ‘)’
(18824,98): run-time error CSS1034: Expected closing parenthesis, found ‘,’
(18824,98): run-time error CSS1042: Expected function, found ‘,’
(18824,137): run-time error CSS1062: Expected semicolon or closing curly-brace, found ‘)’
(18825,63): run-time error CSS1034: Expected closing parenthesis, found ‘,’
(18825,63): run-time error CSS1042: Expected function, found ‘,’
(18825,92): run-time error CSS1062: Expected semicolon or closing curly-brace, found ‘)’ */

Let’s try to understand how to read minification errors. For example check following line.

(17483,98): run-time error CSS1034: Expected closing parenthesis, found ‘,’

Within round bracket , you can see a number 17483 which indicates line number on which there is run time error.

The second number in bracket is 98 which indicates the exact position of character which produces an error on line number 17483.

Now to find out this error location you need to open this file in notepad ++ which is my favorite text editor. And paste all content of your CSS bundle.

Note: Make sure that you need to remove Minification Error lines from notepad++ then go to 17483 line number as shown below.

css_bundling-problem asp.net

Now you can move a cursor on line 17483 and go to 98th character. That’s where the error is!!  Check below screenshot which shows character position in notepad++.

resolve css_bundling_problem

I hope that this tiny blog will be helpful for all ASP.NET MVC Developers.

By | 2017-07-03T16:28:13+00:00 January 28th, 2017|Asp.Net MVC|