Background: I am migrating an ASP.NET
MVC 5
application (developed in Windows 8.1, VS2013
Community, .NET 4.5.1
, MySql
custom membership and role provider) project to Monodevelop
(in Ubuntu 14.4
, Monodevelop
, Mono
).
In my ~/App_Start/BundleConfig
class
public static void RegisterBundles(BundleCollection bundles)
{
BundleTable.EnableOptimizations = true;
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
}
In my ~/Views/Shared/_Layout.cshtml
view
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
In my Web.Config
<add namespace="System.Web.Optimization" />
Also
<compilation defaultLanguage="C#" debug="false"> </compilation>
Also Microsoft.Web.Infrastructure.dll
is deleted from the bin directory.
Problem: I don't see that the bundles are getting rendered when I view source in the browser:
The links are directing towards directories, It should show files in the directories
<link href="/Content/css" rel="stylesheet"/>
<script src="/bundles/modernizr"></script>
What am I doing wrong here?
Bundling reduces the number of individual HTTP requests to server by combining multiple CSS files and Javascript files into single CSS file and javascript file. Minification reduces the file download size of CSS and javascript files by removing whitespace, comments and other unnecessary characters.
The ScriptBundle class represents a bundle that does JavaScript minification and bundling. You can create style or script bundles in BundleConfig class under App_Start folder in an ASP.NET MVC project.
Bundling is the process of rolling up a number of distinct resources together into a single downloadable resource. For example, a bundle may consist of multiple JavaScript or CSS files you bring down to the local machine by making a single HTTP request to an ad hoc endpoint.
For stylesheets you will have to use a StyleBundle and @Styles.Render (). Instead of loading each script or style with a single request (with script or link tags), all files are compressed into a single JavaScript or stylesheet file and loaded together.
ASP.NET MVC API includes StyleBundle class that does CSS minification and bundling. StyleBundle is also derived from a Bundle class so it supports same methods as ScriptBundle.
If @import rules are present in a constructable stylesheet, those rules will be ignored. Support for @import in CSS module scripts may be added to the specification. Track this specification discussion in the GitHub issue.
Same as the script bundle, all the style bundles should be created in the BundleConfig class. under the App_Start folder. The following example shows how to combine multiple CSS files into a bundle.
Inside your BundleConfig file add the following:
BundleTable.EnableOptimizations = true;
Then switch to release mode.
This should do the trick
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