0

When I make change at the css file, the result doesn't appears when I run the app (I tried to clean/rebuild the solution but same problem).

BundleConfig:

...
bundles.Add(new StyleBundle("~/Content/css").Include(
             "~/Content/Index.css",
             "~/Content/Layout.css",
             "~/Content/Login.css"
             ));

Index.cshtml:

@{
  ViewBag.Title = "Index";
  Layout = "../Shared/_Layout.cshtml";
 }
<head>
    <link href="@Url.Content("~/Content/Index.css")" rel="stylesheet" type="text/css" />
</head>

When I check with chrome tool:

enter image description here

In this image the css is not updated when I change at the code.

3
  • Did it work before and now it's just not updating? Commented Apr 20, 2019 at 20:20
  • I think I found the answer, tried with Edge and it shows the updated css Commented Apr 20, 2019 at 20:21
  • 1
    Ctrl + F5 - To refresh and clear cache Commented Apr 20, 2019 at 20:54

1 Answer 1

1

If you don't want the browser to use a cached version of your CSS file, a common solution is to append a query string to the end of the file's URL in your HTML. This is a method of cache busting, and is useful for development/testing when you're making lots of changes to your CSS or JS static files.

Here are a couple of quick ways to achieve this:

  1. Manually add a query string to the end of the URL, and any time you want the browser to request a new version of the CSS file, just change the value:

<link href="@(Url.Content("~/Content/Index.css") + "?v=1")" rel="stylesheet" type="text/css" />

  1. Dynamically add a unique query string. This is useful if you want the browser to request a new copy of the CSS file every time:

<link href="@(<Url.Content("~/Content/Index.css") + DateTime.Now().ToString(yyyyMMddHHmmss))" rel="stylesheet" type="text/css" />

  1. If you're using ASP.NET Core, use a tag helper, which will automatically append a new version number only when there's a change to the file. You just add a simple attribute:

<link href="@Url.Content("~/Content/Index.css")" rel="stylesheet" type="text/css" asp-append-version="true" />

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.