ASP.NET Web Optimization Framework - throws errors - bundling-and-minification

ASP.NET Web Optimization Framework throws errors in CSS minification, I tried, validated and did everything to fix, but seems framework bug
/* Minification failed. Returning unminified contents.
(1,1-2): run-time error JS1195: Expected expression: .
(2,14-15): run-time error JS1004: Expected ';': :
(2,15-19): run-time error JS1306: Invalid numeric literal: 12px
*/
.a {
font-size:12px;
}
;
This was just a single line test to see if it still works but not working.

Fixed. Sorry issue was with the bundle tutorial from where I just copied, its fixed. THanks

Related

SassC error - it doesn't matter what I change, I still get an Invalid CSS message

I've gone through pages of answers and I'm still stumped so here goes:
I'm trying to precompile my Rails app and always get met with a slight variation of this message:
SassC::SyntaxError: Error: Invalid CSS after "...25rem 0}li:not(": expected selector, was
"'.dropdown-menu li'"
on line 6:36279 of stdin
>> in-bottom:.5rem}li{margin:.25rem 0}li:not('.dropdown-menu li'):last-child{ma
------------------------------------------^
stdin:6
I've looked at the CSS in question, and it's fine (no syntax errors, pages render perfectly in the local environment etc). I thought it was a framework issue so I switched from Bulma to another CSSf framework, and I still have the same problem.
Any time I have made a modification (eg removed the selector in its entrirety, the precompile brings up the same problem. Please does anybody know why I'm getting hit with this error?

Bundling CSS CDN

I had a working site before applying minification and bundling. I did not write the original CSS. The problem stemmed from three #import url statements being used to bring in Google fonts.
In an effort to fix the problem, I decided to remove the #import url's from the relevant CSS file and add them individually in my BundleConfig.cs class. However, I cannot figure out the syntax to make this happen:
public static void RegisterBundles(BundleCollection bundles)
{
....
bundles.UseCdn = true;
var templateOriginalPath1
= "http://fonts.googleapis.com/css?family=Lobster";
var templateOriginalPath2 =
"http://fonts.googleapis.com/css?family=Oswald:400,700,300";
var templateOriginalPath3
= "http://fonts.googleapis.com/css?family
=Ubuntu:300,400,500,700,300italic,400italic,700italic";
....
bundles.Add(new StyleBundle("~/bundles/templateOriginal1",
templateOriginalPath1));
bundles.Add(new StyleBundle("~/bundles/templateOriginal2",
templateOriginalPath2));
bundles.Add(new StyleBundle("~/bundles/templateOriginal3",
templateOriginalPath3));
}
Apparently, the syntax was correct. There is a known bug which causes the optimization framework to choke when presented with CSS style sheets which include #import url statements.
The workaround is just too much trouble to be worth it. Hopefully this will be of use to others. I saw first mention of this bug here.
You have to inspect the response headers in the Developer Tools (I use Firefox Developer Browser) to see the details of the error:
/* Minification failed. Returning unminified contents.
(1409,1): run-time error CSS1019: Unexpected token, found '#import'
(1409,9): run-time error CSS1019: Unexpected token,
found '"http://fonts.googleapis.com/css?family=Lobster"'
(1409,57): run-time error CSS1019: Unexpected token, found ';'
(1410,1): run-time error CSS1019: Unexpected token, found '#import'

How to troubleshoot Angular JS Unknown Provider error in minified code

While the app works in debug mode, when release mode switches on .NET bundles, I get the Unknown Provider error. The problem is there many sources (Bootstrap UI and other third-party controls besides application scripts). I fixed a couple of obvious initializers, but this error seems to refer to minified code, generic names:
http://errors.angularjs.org/1.2.21/$injector/unpr?p0=nProvider%20%3C-%20n
How do you troubleshoot something like that?
The way to figure out the problem was to exclude one script file at a time from minification and to see whether the error goes away. The error was actually similar to the one in the question on unknown provider "aProvider <- a" error.
In my case there were several errors. The main one was due to the modal dialog controller, similar to the discussion about injecting modal controller dependencies. However it would only occur with minified code.
The suggestion to provide the controller in the modal options as a string did not work for me. But declaring controller with its dependencies did the trick:
var ModalInstanceCtrl = ['$scope', '$modalInstance', 'items',
function ($scope, $modalInstance, items) { ... }

some time i get unspecified error in js

Sometimes we get "Unspecified error" in IE (javascript error), when using MaskedEdit.application build in framework 2.0
if i enable the debuggin javascript setting then i found this error otherwise a particular part of the page doesnot display.
If we debug we can see that it happens on below line
//only for ie , for firefox see keydown
if (document.activeElement)
{
if (e.id == document.activeElement.id)
{
hasInitialFocus = true;
}
}
when i tried to search where this code is written then i found this code in ajaxcontroltool.dll file.
and this dll is of third party and i can't change in this dll so what should i do to solve the problem.
i tried this in IE8,but i didn't get the error in IE8 it means the code run smoothly/errorless in IE8.
i get this error in IE9 as occurence ratio of once in 6 times open a page.
it became my headache if any one know please help me out of this.
It looks like a browser issue or dll issue.
Has anyone else noticed this?
Thanks and regards
shoaib
and this dll is of third party and i can't change in this dll so what should i do to solve the problem
Actually you can, as the AjaxControlToolkit is an open source project. You can download project source code from the CodePlex: http://ajaxcontroltoolkit.codeplex.com/ and customize it for your needs

Minify Html output of ASP.NET Application

What are the ways by which we can reduce the size of the HTML Response sent by an asp.net application?
I am using Controls which are not owned by me and it produces output with white spaces. I am interested in Minifying the entire HTML output of the page just like how google does (View source www.google.com) to improve the timing.
Is there any Utility classes available for ASP.NET which can do this stuff for me?
There is no need to do it at run time. Because it can be done at compile time.
Details: http://omari-o.blogspot.com/2009/09/aspnet-white-space-cleaning-with-no.html
Try HTTP module as described here: http://madskristensen.net/post/a-whitespace-removal-http-module-for-aspnet-20
For Microsoft .NET platform there is a library called the WebMarkupMin, which produces the minification of HTML code. For each ASP.NET framework has its own module:
ASP.NET Core - WebMarkupMin.Web. Implemented as an HTTP module, so it can work with any framework. Suitable for use in the ASP.NET Web Pages framework (Razor).
ASP.NET MVC - WebMarkupMin.Mvc
ASP.NET Web Forms - WebMarkupMin.WebForms
Documentation is available at - http://webmarkupmin.codeplex.com/documentation
I want to comment on Thorn's suggestion (but I'm new to stack overflow).
The linked code (omari-o.blogspot.com) doesn't support MVC4, and although the code is open source it cannot easily be upgraded because of braking changes between MVC3 and MVC4.
There might be whitespaces written to the http result at runtime, only the developer of the actual site can know that. Thus static minification of template files (aspx) is not foolproof at all. Dynamic minification, which is suggested by gius, should be used to guarantee that whitespaces are removed correctly, and unfortunately this will incur a runtime computation cost. If code dynamically writes spaces to the output, it will have to be removed dynamically.
The accepted answer does not work with MVC 4, so here is a similar lib that minifies at build-time https://github.com/jitbit/HtmlOptimizerMvc4
Just adding another option I do not see listed here, which is the one I was recommended using:
Html minifier command line tool
Usage:
here and here
There is an issue, however, with this tool: it leaves single line (//) comments, and it causes problems for Razor parsing, since a single line comment placed within a C# block like the following:
#{
...
...
// anything
...
}
will cause the minification output rest of the line, from this point on, to be ignored by the Razor parser, which will thus raise an error stating there it could not find the closing "}" for the block.
My workaround for this issue was to completely removing these comments from the output.
This way it works.
To do that, simply remove the RegexOptions.SingleLine from line 145:
htmlContents = Regex.Replace(htmlContents, #"//(.*?)\r?\n", ""/*, RegexOptions.Singleline*/);

Resources