tarzanbappa
tarzanbappa

Reputation: 4958

Clearing Browser Cache when deploy a new release

I've a ASP.Net MVC + angular web application. And about 500 + users are using the application.

The problem is whenever we do a new publish/ release we have to say the users to clear their browser cache. This is annoying for the users.

How other websites such as facebook etc.. manage the browser cache when they update their application/site since we don't clear our browser cache too often.

Is there any way to automatically clear borwser cache when there is a new release.

Upvotes: 7

Views: 8305

Answers (3)

Riv
Riv

Reputation: 1859

With ASP.Net Core MVC you can use the asp-append-version TagHelper for your script files. It calculates a hash of the file and appends it to the filename:

<link rel="stylesheet" type="text/css" href="myfile.css" asp-append-version="true" />    
<script src="myfile.js" asp-append-version="true"></script>

so the files would become something like this:

<link rel=stylesheet href="myfile.css?v=qWYa_XOt9FCnEt2z8CjC7apiyjA5l9UA9UCqT028LI">
<script src="myfile.js?v=eN9kwxdWtX5aP8H3TFVOQrwu08Qndyktg5kvpSLa1A">

Upvotes: 5

Alex Pollan
Alex Pollan

Reputation: 873

You can set up cache busting via a task runner: grunt, gulp, etc.

By using file calculated hashes you also can make your cache breaking smarter. That way a file will be cached only if it changes (thereby improving performance).

Please check this for an example: https://github.com/shakyShane/grunt-cache-breaker (similar modules are available for other task runners)

Upvotes: 0

brk
brk

Reputation: 50291

You can add a version number to your file like this

<script type="text/javascript" src="pathTofile.some.js?v1"></script>

The text after ? can be anything.The query string will help in avoiding cache & browser will load a different file and invalidate the one in cache

Upvotes: 1

Related Questions