DEV Community

Armen Hovsepian
Armen Hovsepian

Posted on

3

Fixing browser caching problems in ASP.NET Core

In order to fix browser caching in ASP.NET Core you can use "asp-append-version" tag helper in your website images, CSS links, and javascript references. If you use this tag helper and set it true a version suffix will be appended to your resource and when you change the file on the server the version of the file will be changed and the browser noticed and automatically downloads the new version as well.
Here are some examples:

<img src="~/images/banner1.jpg" width="100%" asp-append-version="true"/>

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

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

 // Result
<img src="/images/banner1.jpg?v=jGW_rax5TkGDuL0z_GnDkSZTmmFqdGRzA8pXnJnug7c" width="100%">

<link href="/css/site.css?v=t2uNA6b681W1KvNxE6O-pzzaJGt2penW9dzO1CxKNns" rel="stylesheet"/>

<script src="/js/site.js?v=ji3-IxbEzYWjzzLCGkF1KDjrT2jLbbrSYXw-AhMPNIA"></script>
Enter fullscreen mode Exit fullscreen mode

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay