Every time I deploy an MVC web application my server has to re-cache all js and css bundles.
Because of this it can take several seconds for the first view to render after deploying.
Is there a way to pre-cache bundles? After all, the files are static at compile time.
Solution
To fix we replaced the default memory cache with caching that persisted beyond the App Pool life.
To do this we inherited from
ScriptBundle
and overrodeCacheLookup()
andUpdateCache()
.Complications
The only other wrench worth noting had to do with our persistent caching tool. In order to cache we had to have a serializable object. Unfortunately,
BundleResponse
is not marked asSerializable
.Our solution was to create a small utility class to deconstruct
BundleResponse
into its value types. Once we did this we were able to serialize the utility class. Then, when retrieving from the cache, we reconstruct theBundleResponse
.