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.

Devy
  • 703
  • 6
  • 17

1 Answers1

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" />
Versailles
  • 441
  • 2
  • 6