0

I understand that when using bundles for JavaScript and CSS the web application is caching the bundles and using a caching key for it, something like the following:

<script src="/bundles/sampleJs?v=h-HGvCLcx-0T1kG3DBKIVBtGxEhtfpONQl5b_7BQuSo1"></script>

How can I programmatically refresh the cached bundles (or just one bundle)?

For example, if I have to upload a new CSS update - I want to update the bundles without having to restart the whole web application...

danludwig
  • 46,965
  • 25
  • 159
  • 237
Yovav
  • 2,557
  • 2
  • 32
  • 53
  • That would heavily depend on what web framework you are using; please add a tag (since it is not a matter of JavaScript or CSS, and not the responsibility of Bundler). – Amadan Jan 01 '15 at 03:49

1 Answers1

0

Here are two ways you can address the issue:

ASP.NET:

If the html page is generated on the server side in let's say ASP.NET, I would simply define a static global in Global.asax that would be appended to all resources.

<script src="/bundles/sampleJs?cacheBustVersion=" + <%= @cacheBustVersion %> ></script>

RequireJS:

In Javascript, if you're using RequireJS you can create a variable called urlArgs in your requirejs config section.

urlArgs: "cacheBustVersion=v1"

This will append "&cacheBustVersion=v1" to each file that's loaded via the require call.

RequireJS during development:

urlArgs: "cacheBustVersion=" Date.now()

This will ensure all files loaded through requireJS are not cached.

RequireJS Documentation for urlArgs

Community
  • 1
  • 1
Nick
  • 4,002
  • 4
  • 30
  • 41
  • Hi. I actually want to take advantage of the cached bundles, only I was looking for a way to somehow cause the built-in bundle mechanism to re-do the bundling and minification of the bundled files when I update a CSS file for example... – Yovav Jan 01 '15 at 04:36