2

I trying to bundle scripts and styles bootstrap for my application. My debug is working But when I publish it, don't load scripts and styles.

I add a BundleConfig (BootstrapBundleConfig)

public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/js").Include(
            "~/Scripts/jquery-{version}.js",
            "~/Scripts/jquery-ui-1.10.4.custom.js",
            "~/Scripts/jquery-migrate-{version}.js",
            "~/Scripts/bootstrap.js",
            "~/Scripts/gridmvc.js",
            "~/Scripts/gridmvc.lang.fa.js",
            "~/Scripts/jquery.validate.js",
            "~/scripts/jquery.validate.unobtrusive.js",
            "~/Scripts/jquery.validate.unobtrusive-custom-for-bootstrap.js",
            "~/scripts/entitypicker.js",
            "~/scripts/js-persian-cal.js",
            "~/scripts/json2.js",
            "~/scripts/bootbox.js",
            "~/Scripts/jalali.js",
            "~/Scripts/calendar.js",
            "~/Scripts/calendar-setup.js",
            "~/Scripts/lang/calendar-fa.js"
            ));
        bundles.Add(new StyleBundle("~/content/css").Include(
             "~/Content/bootstrap.css",
             "~/Content/bootstrap-responsive.css",
             "~/Content/bootstrap-mvc-validation.css",
             "~/Content/themes/ui-lightness/jquery-ui.css",
             "~/Content/js-persian-cal.css",
             "~/Content/entitypicker.css",
             "~/Content/gridmvc.css",
             "~/Content/aqua/theme.css",
             "~/Content/calendar-system.css"
            ));

    }

add register this in Global

BootstrapSupport.BootstrapBundleConfig.RegisterBundles(System.Web.Optimization.BundleTable.Bundles);

and set styles/script in _layaout

<link href="@Styles.Url("~/content/css")" rel="stylesheet" />
@Scripts.Render("~/js")

But when publish it, and open View Page Source

    <link href="/Content/css?v=65vDyivXbF9ucPBBLls9CVnwUcCNass7hOMNUEXbN-I1" rel="stylesheet" />

and when open this file get error in first line.

/* Minification failed. Returning unminified contents.
(962,1): run-time error CSS1019: Unexpected token, found '@charset'
(962,10): run-time error CSS1019: Unexpected token, found '"UTF-8"'
(962,17): run-time error CSS1019: Unexpected token, found ';'
(994,1): run-time error CSS1019: Unexpected token, found '@-webkit-keyframes'

I search in google and used different methods, but the error is not resolved.

  1. add all style to a special path (Content/Them/Bootstrap) and use new StyleBundle("~/content/Them/Bootstrap")

  2. use BundleTable.EnableOptimizations = true;

other..

Colin Bacon
  • 15,436
  • 7
  • 52
  • 72
Niloo
  • 1,205
  • 5
  • 29
  • 53

4 Answers4

1

This usually occurs if your css files are not well formatted, put your css code to test using http://csslint.net/.

Also instead of using this line

<link href="@Styles.Url("~/content/css")" rel="stylesheet" />

you could use this

@Styles.Render("~/content/css")

If you want to debug this without publishing you could add this line to your RegisterBundles method of your BundleConfig:

BundleTable.EnableOptimizations = true;
Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281
  • Thanks, I test css and I correct any errors(don't correct warnings). and use `@Styles.Render("~/content/css")`. it is remove errors when see css file in publish but don't load styles file. :( – Niloo Jul 16 '14 at 04:16
  • If it was a incorrectly style why would it work when running locally? Surelt i has something to do with file permissions when you publish? – Zapnologica Apr 22 '15 at 09:21
1

This is the culprit @charset "UTF-8". Search through your css files and see if you can find it. This needs to be at the top of the bundled css file. i.e. At the top of the first CSS file in the bundle list. If it is not it will fail to minify.

It is often used when there are Unicode characters in the CSS file. And this is normally because of the use of an icon font like font awesome. But if you don't need it in your CSS file, then just take it out.

Colin Bacon
  • 15,436
  • 7
  • 52
  • 72
0

Your css has some 'problems' when minifying. this can be because of bad css or bad optimization.

Try to validate your CSS and see if you can spot the culprit.

For a workaround use BundleTable.EnableOptimizations = false which won't minify the css.

To 'debug' this on local host, change your web config and remove the attribute debug=true (this will make your css minify on your dev machine)

Also having different folder base on your bundle will make any relative url (like a background image) on your stylesheet to not work.

Bart Calixto
  • 19,210
  • 11
  • 78
  • 114
0

https://stackoverflow.com/a/19544226/2440976 -This is a dup question I believe - Here is likely the simple answer (It worked for me!)

(From answer) IIS Config>Authentication>RightClickOn Anonymous Auth>Click Edit> Check Application pool identity

Community
  • 1
  • 1
Danimal111
  • 1,976
  • 25
  • 31