Search code examples
asp.net-mvc.net-4.5bundling-and-minificationasp.net-optimization

ASP.NET bundling/minification: including dynamically generated Javascript


I have a site that dynamically generates Javascript. The generated code describes type-metadata and some server-side constants so that the clients can easily consume the server's services - so it's very cacheable.

The generated Javascript is served by an ASP.NET MVC controller; so it has a Uri; say ~/MyGeneratedJs.

I'd like to include this Javascript in a Javascript bundle with other static Javascript files (e.g. jQuery etc): so just like static files I want it to be referenced separately in debug mode and in minified form bundled with the other files in non-debug mode.

How can I include dynamically generated Javascript in a bundle?


Solution

  • Darin is right, currently bundling only works on static files. But if you can add a placeholder file with up to date content, bundling does setup file change notifications which will detect automatically when the placeholder file changes.

    Also we are going to be moving to using VirtualPathProviders soon which might be a way to serve dynamically generated content.

    Update: The 1.1-alpha1 release is out now which has support for VPP