Visual Studio Development Server not updating css and javascript? Visual Studio Development Server not updating css and javascript? asp.net asp.net

Visual Studio Development Server not updating css and javascript?


The server may be sending headers to the browser that cause it to keep using cached copies. The simple way to test this is to empty your browser cache.

If that fixes it, you need to study the HTTP headers you get from the server. The developer tools (a.k.a. F12 tools) in your browser of choice will expose the headers returned by the server. Then decide if you want to keep using these caching settings (good for speed) or change them (good for development).

And how do you adjust these headers, you ask? It depends on the server. Here is a link to the instructions for common servers:


A quick way is to add random parameters after the script or css file's src attribute.for example

<script type="javascript" src="@Url.Content("~/scripts/myScripts.js?" + DateTime.Now.ToString("ddMMHHmmss")"></script>

so browser will always assume its a new file and will not cache.

Be sure to remove this when deploying on live server.


If you always want to get the last version of js and CSS files, you could modify your StaticFile middleware like

app.UseStaticFiles(new StaticFileOptions(){    OnPrepareResponse = context =>    {        context.Context.Response.Headers.Add("Cache-Control", "no-cache, no-store");        context.Context.Response.Headers.Add("Expires", "-1");    }});

or you could add asp-append-version="true" to your file references like:

<link rel="stylesheet" href="~/css/site.css" asp-append-version="true"/>