asp.net-mvcbundling-and-minificationsystem.web.optimization

Loading an MVC JS bundle externally


I have a small JS library in my MVC 5 project that I want to be available for external users to load into their apps. At the moment I'm bundling it like so:

bundles.Add(new ScriptBundle("~/clientApi")
    .IncludeDirectory("~/Api/clientapps/", "*.js"));

I can then access the bundled library via browser at the path /clientApi.

However, it's always minified, even though I've set my web.config debug=true, and other bundles in my own app are included as non-minified.

How can I make the file/s in the bundle available as a non-minified bundle file?


Solution

  • If you access /clientApi directly then yes it will be the bundled/minified version.

    The debug=true option effects your script reference in your own .cshtml file. When debug=true, references to the individual script files are rendered to the client (so the client doesn't use /clientApi at all).

    When debug=false, then a reference to /clientApi (with the version query string) is rendered to the client instead, so they get the bundled/minified version... If you give that link to these external users, then that is what is going to get rendered.

    That path doesn't care if it is debug or not. It's not like /clientApi is going to bundle but not minify the files depending on your compilation settings... it's just either your app is going to render the bundled/minified path or the individual script paths.

    If you want to do debugging/testing in external apps, then they will just have to use the individual script paths.

    Even if you do give these external apps the /clientApi reference once testing is done and they are ready to use the bundled/minified version, it doesn't explain how you are going to handle versioning. If you update a script, how will they know to stop caching?