I have created MVC application. When I publish the application on Azure with release option, all css and js file load in a single bundle in page. (Open view source of page then displays a single link for css).
When I publish a site with Debug option in publish profile then all CSS load individual.
My problem is when publish site with release option theme not load correctly, but with debug option theme loads correctly. I want to publish my application with Release option only. If anyone face this issue before and get any solution then please help me.
The following example shows how to combine multiple CSS files into a bundle. public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { bundles. Add(new StyleBundle("~/bundles/css"). Include( "~/Content/bootstrap.
Click on wwwroot folder, select the css file you want minified, then right click and choose bundler & minifier. Then from popup minify file. It will be the same file name with the minified version.
I have experienced this before when using bundling.
Say for instance your css file is located at: /Content/css/css.css
This css file then makes a reference to another file, or for example an image at /Content/images/image1.png
via url('../images/image1.png')
.
You then set up your css bundle @ /bundles/css
.
All appears great in debug mode. However, when you set <compilation debug="false" ....
in your web.config, suddenly the references made in the css file breaks. If you open your console in Firebug/Chrome dev tools and check the network tabs, you'll see resources failing to load, from an incorrect URL.
This happens because when debug mode is off, all the files are bundled and minified like they would be in production. In this case, the CSS file would be bundled and served from the URL /bundles/css
. This results in the relative URL reference breaking. Where it once referenced /Content/images/image1.png
, it now references /images/image1.png
.
You have a few options to solve this:
/Content/css/cssbundle
. This can become very tedious quickly.../images/image1.png
would become /Content/images/image1.png
. This does mean you can't use a lot third party CSS bundled out of the box, you would have to check/change relative references if you wanted to bundle them.The main differences of StyleTransformer and ScriptTransformer classes from a standard implementations: ability to exclude unnecessary assets when adding assets from a directory, does not produce the re-minification of pre-minified assets, support automatic transformation of relative paths to absolute in CSS-code (by using UrlRewritingCssPostProcessor), etc.
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