Reputation: 1623
In my ASP.NET app, I have several pages/scripts that I can't bundle - PDF.js viewer page or MediaElement video loader.
But sometimes I do minor amendments to those scripts; I need to version/cache-bust the respective script files, so these are auto-reloaded for users. In PDF.js viewer.html, for example:
<script src="viewer.js?v=1.1"></script>
The gotcha is: how to make ASP.NET/IIS auto-inject the version info into the static HTML files that it serves? Any solutions?
Thank you in advance.
Upvotes: 1
Views: 225
Reputation: 1746
Do you use any type of task runner?
I use Gulp, and whenever I build, I have a task to replace my version number with something unique to ensure the latest version is always requested.
So in my Index.cshtml
:
<script type="text/javascript" src="~/bundle.js?v=$$VERSION" charset="utf-8"></script>
And in my gulpfile.js
:
gulp.task('version', function () {
return gulp.src('index.html')
.pipe(replace('$$VERSION', Date.now()))
.pipe(gulp.dest('dist'));
});
Upvotes: 1