Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publishing a website is not updating my CSS bundles

When I run my code from Visual Studio in release mode, and check the bundled style sheet, I can see my updates to the css files in that bundle. However when I publish the website to the server or my local machine, my changes in the style sheets have not come through. The bundled style sheet is still the old one.

I have tried an IIS reset, a clean build/rebuild, deleted all files from the IIS folder and re-published.

I am using LESS if that makes any difference.

My bundle config:

bundles.Add(new StyleBundle("~/bundles/requiredStyles").Include(
    "~/Content/Style/Libs/bootstrap.min.css",
    "~/Content/Style/Libs/font-awesome.min.css",
    "~/Content/Style/Globals/application.css",
    "/Content/Style/Libs/muliDropdown.css",
    "~/Content/Style/Libs/smoothDivScroll.min.css",
    "~/Content/Style/Libs/jasny-bootstrap.min.css"
));

I'm checking the bundled css by visiting http://www.mywebsite.com/bundles/requiredStyles

So I made a change in application.css which is fine if I hit play in visual studio (in release mode), but when I publish to my local IIS, my change is no longer there.

like image 281
garethb Avatar asked Feb 12 '15 05:02

garethb


People also ask

Why is my CSS not updating on my website?

Browser Cache If you are adding/modifying in-line CSS or JavaScript and not seeing the changes reflected in the HTML source, the page is likely being cached. The solution may be to purge the WordPress object cache, which stores our page caching (Batcache) renders.

Why my CSS is not reflecting?

The most common reason is that your CSS file is cached by your browser. To fix this, try force refreshing your browser (Ctrl + F5). If that doesn't work, try clearing your browser's cache. Another possible reason is that you have not uploaded the CSS file to the correct location on your server.

Why sometimes my CSS is not working?

If you put the <link> tag inside another valid header tag like <title> or <script> tag, then the CSS won't work. The external style CAN be put inside the <body> tag, although it's recommended to put it in the <head> tag to load the style before the page content.


2 Answers

This can happen if you have a minified version of a css file in the same directory as your unminified file.

For example, if you have the following files:


    ~/Content/bootstrap.css
    ~/Content/bootstrap.min.css

in your directory, and you register the "bootstrap.css" file in your bundle, the optimizer will first attempt to use the "bootstrap.min.css" file during publish. If you only updated the "bootstrap.css" file and did not update the "bootstrap.min.css" file, you will get the old styles from "bootstrap.min.css". You can fix this problem by deleting the "bootstrap.min.css" file or by updating it.

This does not happen in a debug build because it does not pull the minified files if your compilation is set for debug using the following:

<system.web>
    <compilation debug="true" />
    <!-- Lines removed for clarity. -->
</system.web>

You can also overwrite the web.config setting by disabling the optimizations via:


    BundleTable.EnableOptimizations = false;

This would go inside your BundleConfig.cs file.

like image 89
Filip Stanek Avatar answered Oct 10 '22 04:10

Filip Stanek


In my case bootstrap.min.css also exists in content folder which I removed it and web site working fine.

as per Filip Stanek mentioned "the optimizer will first attempt to use the "bootstrap.min.css" file during publish"

even if we didnt add it in bundle config while publishing code it point to "bootstrap.min.css"

like image 23
Dhruv Patel Avatar answered Oct 10 '22 04:10

Dhruv Patel