I am creating a style bundle:
bundles.Add(new StyleBundle("~/content/bundled-styles.css").Include(
"~/content/flexisel-style.css"));
... and in my view:
@Styles.Render("~/content/bundled-styles.css")
If I view my page without optimizations enabled (i.e. BundleTable.EnableOptimizations = false;
) then everything works fine. My .css file gets added to the page without any problems and it contains all the styles.
If I set BundleTable.EnableOptimizations = true;
(without changing anything else) then the generated .css bundle doesn't contain any styles. The bundled .css file is added to the page along with the generated token but when I click on the .css file from the page source, it is completely blank. My page then is obviously rendered without any styling.
Additional information:
The minified CSS file does not need to be listed in the bundle. In most cases, you’ll just want the default style link rendering, which is how the file Site.css is included in the Master Page in the default WebForms project.
When minification occurs, which is normally only in release/production, the optimizer will automatically minify the CSS files referenced in the bundle. However, if a minified file is detected, it will use that file.
webopt:BundleReference: Links to individual css files in the bundle, sent in their original format (no minification). Styles.Render: Links to individual css files in the bundle, sent in their original format (no minification).
Setting debug="true" will result in all CSS bundles being bundled, minified, and version-stamped. (Note that Styles.Url () partly ignores this value – see details in next section.)
I just had this issue as well. It seems as if the bundler did not like the extension in the name. Once I removed the extension, the bundler started to work.
You might try doing the following. Notice I've removed the .css
in two places.
Remove the .css
bundles.Add(new StyleBundle("~/content/bundled-styles").Include(
"~/content/flexisel-style.css"));
@Styles.Render("~/content/bundled-styles")
I was stuck on this for a very long time, i was trapped by the following:
that if the key you’re using for your bundle, in this case “~/scripts”, matches the virtual path of the file included in the bundle, then it will not be included. To fix this, I changed the key to “~/bundles/scripts” and everything is happy now.
Credits: https://samrueby.com/2015/03/05/asp-net-mvc-bundleconfig-scripts-returning-an-empty-response/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With