I use a .cshtml
file to generate a dynamic .js
file in an ASP.NET MVC controller. So the .js
file never exists on disk, but only in memory at runtime. It works like this.
The browsers loads a javascript...
<script async src='http://example.com/script.js'></script>
...that is fetched from and generated by my MVC Controller endpoint:
[HttpGet]
[Route("script.js")]
public ActionResult GetScript()
{
// This takes a .cshtml template-file and returns a generated .js file
return new JavascriptViewResult(viewName, viewModel);
}
Is there a way to minify the resulting javascript file that is returned in runtime? I had a look at System.Web.Optimization.JsMinify
but I'm not sure how I would get that to work. Can I write some kind of HttpHandler
? Is there maybe a better approach to solve this problem?