Change an appsettings.json value on publish netCore6

Viewed 27

Is it possible to increase a value in the appsettings.json when I publish a project?

I want to add some kind of number to all css and js files, because it seems they keep getting cached. I want a value in my appsettings.json (or somewhere), I'll add to all css/js includes. When I publish the project, I would like this number to increase.

Is there a way to do this? Or is there some other way to force a refresh of css/js on the client-side when changes are made?

1 Answers

You can use the built-in asp-append-version if you're referencing your CSS and JS files directly. Like

<script src="your-file-here.js" asp-append-version="true"></script>

That will append a "version" to the file path (which is calculated from a hash of the file content, thus it will update whenever the file does). In my experience it works pretty well :-)

https://www.c-sharpcorner.com/blogs/aspappendversion-feature-in-asp-net-core

Related