I'm working on a web application that has a lot of js scripts packed into bundles using System.Web.Optimization
library.
In order to reduce the response time for first users I prepare all the bundles in Application_Start
and force adding them to cache. Of course, that increased the time of Application_Start
in return.
I managed to save the result of GenerateBundleResponse()
to files and then just load the content of these files into cache in Application_Start
, but it requires to run the application twice: the first "cold" start prepares the scripts and saves them to files, while the second can use the prepared scripts and starts really fast.
public abstract class FileBasedBundle : Bundle
{
public override BundleResponse GenerateBundleResponse(BundleContext context)
{
if (File.Exists(bundlePath))
{
var content = File.ReadAllText(bundlePath);
var fileList = GenerateFileList(context);
return new BundleResponse(content, fileList);
}
var response = base.GenerateBundleResponse(context);
File.WriteAllText(bundlePath, response.Content);
return response;
}
}
The question is: how can I prepare the bundles in some util or script for deploy on remote machines in order not to start the application twice? Are there any alternatives to System.Web.Optimization to run outside web app context? Thanks!