Cache busting SPA MVC

Sami C.
1 min readOct 11, 2019

--

If you’re referencing app.js inside your cshtml razor file. You might end up with a caching issue.

To fix this caching issue for SPA applications hosted inside an MVC shell you can simply use the “asp-append-version” attribute.

asp-append-version=”true”

MVC will generate a hash of your file and renders this to your script or link tag. This is exactly what we need!

<script asp-append-version="true" src=~/dist/js/app.js></script>

This means when your file changes it will calculate another hash which is basically another version.

Happy coding!

--

--

Sami C.
Sami C.

Written by Sami C.

Freelance Software Engineer

No responses yet