Question

Can anyone tell me what causes/triggers Squishit to rebuild a bundle in production mode?

For example, if I create the following bundle, the file 'Site.Master_{GUID}.css' is created as expected.

<%= Bundle.Css()
   .Add("~/css/reset.css")
   .Add("~/css/typography.css")
   .Add("~/css/styles.css")
   .Add("~/MasterPages/Site.Master.css")
   .Render("~/Cache/Site.Master_#.css")
%>

But if I delete the file bundle file it does not get re-created. I have found, by trial and error, that if I change the web.config file to

<compilation debug="true" targetFramework="4.0" />

and then back to false

<compilation debug="false" targetFramework="4.0" />

the next time the page is requested then the bundle is rebuilt, but I would like to know:

a) how Squishit decides whether the particular bundle should be built or rebuilt

b) if there is a recognised way of resetting Squishit to rebuild all the bundles - after a cache clean-out or site update for example.

Thanks.

Was it helpful?

Solution

SquishIt doesn't really decide whether the particular bundle should be built or rebuilt - if a bundle is present in SquishIt's cache it assumes the file is still there. This is by design, as it would get very expensive to check the file system each time the bundle cache is accessed.

Because the bundles are cached in HttpRuntime.Cache you can force reconstruction by clearing the relevant items from the cache. A prefix of "squishit_" is used on all items added, and after that "css" or "js" can be used to delineate on asset type. Anything that clears the cache should result in bundles being rebuilt, including site reset (which your web.config change sets off). If you need a backdoor way to control this at runtime maybe something like this could be modified to suit your needs.

Another thing that will cause a bundle to be rebuilt is a change to one of the files included in its content. This is controlled via CacheDependency when the bundles are initially added to the cache.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top