Scott Hanselman today blogged about Smidge. I think the library is pretty nice and I'm evaluating the library.
I like the option to define logic for Debug and Production like in the sample:
bundles.CreateJs("test-bundle-3", "~/Js/Bundle3")
.WithEnvironmentOptions(BundleEnvironmentOptions.Create()
.ForDebug(builder => builder
.EnableCompositeProcessing()
.EnableFileWatcher()
.SetCacheBusterType<AppDomainLifetimeCacheBuster>()
.CacheControlOptions(enableEtag: false, cacheControlMaxAge: 0))
.Build()
However I couldn't find out what defines Debug
/Production
. Is there a way to tell the system when he's in debug and when he is in production mode?
Also seems that the Version can only be defined in the config.
"smidge": {
"dataFolder" : "App_Data/Smidge",
"version" : "1"
}
Is there an option do define the version in the code?
Is there a way to tell the system when he's in debug and when he is in production mode?
This is covered in the docs here: https://github.com/Shazwazza/Smidge/wiki/Rendering#debugging and it's based on the debug="true"
attribute of the html tag.
Also seems that the Version can only be defined in the config.
The Version is controlled in Smidge by the Smidge.Cache.ICacheBuster
. There are currently 2 implementations of this:
/// <summary>
/// Based on a static string specified in config
/// </summary>
public class ConfigCacheBuster : ICacheBuster
/// <summary>
/// Creates a cache bust value for the lifetime of the app domain
/// </summary>
/// <remarks>
/// Essentially means that all caches will be busted when the app restarts
/// </remarks>
public class AppDomainLifetimeCacheBuster : ICacheBuster
So it's possible to specify one of these or implement your own. If you implement your own, you need to add it to your container like:
services.AddSingleton<ICacheBuster, MyCacheBuster>();
Then you can specify options for your bundle (there are various ways to do this), for example:
bundles.CreateJs("test-bundle-2", "~/Js/Bundle2")
.WithEnvironmentOptions(BundleEnvironmentOptions.Create()
.ForDebug(builder => builder
.EnableCompositeProcessing()
.SetCacheBusterType<MyCacheBuster>())
.Build()
);
You can also see this startup class for examples: https://github.com/Shazwazza/Smidge/blob/master/src/Smidge.Web/Startup.cs#L126