Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC: When does script bundling decide to change the version of a bundle?

I used to put "?v=n" at the end of my scripts references, like:

<script type="text/javascript" src="@Url.Content("~/Scripts/Foo.js")?v=2"></script>

Each time I edited a .js, I added 1 to that versioning, eg:

<script type="text/javascript" src="@Url.Content("~/Scripts/Foo.js")?v=3"></script>

I decided this couldn't continue being like that (I have too many scripts now), so I started using the ASP.NET MVC bundling feature (BundleConfig, BundleCollection, RegisterBundles, et c).

Indeed a version is automatically assigned to the bundle:

<script src="/Scripts/Bundles/Foo?v=EjpuCsTAfNN9NMv5E8hER41p25Zj9w6ncqWRsYdqQUY1"></script>

My question is:
When does that version change? Can I rely on this? How does it work internally?

I might be wrong but one time I had to manually refresh the browser so that the script was updated, because the minor change I did to the script didn't took effect on the version.

What could have caused this?
Are minor changes considered in the versioning?

like image 507
sports Avatar asked Apr 05 '14 04:04

sports


1 Answers

How does .net generates the version of bundle?

The version of bundle is a SHA256 based hash of all bundled content.

So if you will change any data of bundled files - version will be changed.

like image 119
Dmitry Zaets Avatar answered Nov 06 '22 09:11

Dmitry Zaets