Smidge
Smidge copied to clipboard
SmidgeHelper.RequiresCss doesnt work
If I try to use this in my view SmidgeHelper.RequiresCss(new CssFile("~/css/site.css")); and later @await SmidgeHelper.CssHereAsync()
it generates a url to a file that doesnt exist:
The folder is created correctly in the cache folder (and it contains the right file):
but it seems it never gets compressed, and thus cannot serve it.

Config:
var smidgeConfig = builder.Configuration.GetSection("smidge");
smidgeConfig["dataFolder"] = config.TemporaryFolder;
var smidgeFiles = new PhysicalFileProvider(smidgeConfig["dataFolder"]);
services.AddSingleton<ISmidgeFileProvider>(new SmidgeFileProvider(builder.Environment.WebRootFileProvider, smidgeFiles))
.AddSmidge(smidgeConfig)
.AddSingleton<PreProcessPipelineFactory, NuglifyJsPreProcessPipelineFactory>()
.Configure<SmidgeOptions>(o => {
var def = o.DefaultBundleOptions;
var prod = def.ProductionOptions;
prod.FileWatchOptions.Enabled = true;
def.DebugOptions = prod;
})
.AddSmidgeNuglify(new(new NuglifyCodeSettings(new() {LineBreakThreshold = 200}) {SourceMapType = isDevelopment ? SourceMapType.Inline : SourceMapType.None},
isDevelopment ? CssSettings.Pretty() : new()));
...
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions {FileProvider = smidgeFiles, RequestPath = "/smidge-static"});
...
app.UseSmidge();
app.UseSmidgeNuglify();
internal class NuglifyJsPreProcessPipelineFactory : PreProcessPipelineFactory
{
public NuglifyJsPreProcessPipelineFactory(Lazy<IEnumerable<IPreProcessor>> allProcessors) : base(allProcessors) { }
private static PreProcessPipeline? _js;
private static PreProcessPipeline? _css;
public override PreProcessPipeline CreateDefault(WebFileType fileType) =>
fileType switch {
WebFileType.Js => _js ??= new(new[] {Resolve(typeof(NuglifyJs)),}),
WebFileType.Css => _css ??= new(new[] {Resolve(typeof(NuglifyCss)),}),
_ => throw new ArgumentOutOfRangeException(nameof(fileType), fileType, null)
};
}
Js has same problem, but bundles (for both css and js) works just fine
@SmidgeHelper.CreateJsBundle("hest").RequiresJs(new JavaScriptFile("~/js/JavaScript.js"));
@await SmidgeHelper.JsHereAsync("hest");

using version 4.0.3
Sorry for the delay so this is for view based declarations only. Do you know if this works OOTB without custom config mods? In the test project this is working:
- https://github.com/Shazwazza/Smidge/blob/master/src/Smidge.Web/Views/Home/Index.cshtml#L29
- https://github.com/Shazwazza/Smidge/blob/master/src/Smidge.Web/Views/Home/Index.cshtml#L43
Any updates on this?
Hey @Shazwazza, I've just run into the same problem. Tried to reproduce in a simple setup but works fine, so unsure what the cause is so far.
What I do know is that its trying to load the file from the cache e.g.:
\Smidge\Cache\LAPI\638024650700000000\593ec4e4.js
But the file is actually located at:
Smidge\Cache\LAPI\638024624350000000\593ec4e4\4070e81a.js
Seems like its missing the filename when looking for the file.
I'll keep you posted if I figure it out.
What cache buster are you using? If it's the default, bump your version number and it should work. Sounds like you have changed things and haven't bumped your version number so it's loading old content.
Also note view based declarations can be tricky if you are doing things in the wrong order (i.e. creating or adding to bundles in partial views but trying to render the dynamic bundle before they execute).
Thanks Mate, Yeah, tried bumping the version, and yes it's called from a partial, but the @await SmidgeHelper.JsHereAsync() call is the last thing before the close body in my case.
Cachebusting is set in Appsettings.json as "AppDomain", however overriding it in code in dev as "TimestampCacheBuster"
The whacky thing is that I'm running locally, so all my bundled CSS are being served individually, however after adding a js/css file without the bundling e.g.: SmidgeHelper.RequiresJs("/Scripts/javascript.js"); it seems to be coming from the cache?
It seems to be caching required files in both my project where its broken and the clean project, where it works.
Just as an FYI: I have a custom pipeline to include a Dotless .less processor, so it's not the usual setup.
- The clean project that I'm trying to reproduce it in works with/without the custom pipeline.
- The broken project still fails If I don't include the custom pipeline.
I'm a little stumped at whats different between the two projects :)
FYI In Umbraco 11, the following change caused some CSS to appear but url doesnt appear to take notice of appsettings config.
Original code:
@{
await SmidgeHelper.CssHereAsync();
}
changed to @await SmidgeHelper.CssHereAsync()
appsettings.json
"smidge": { "dataFolder": "Smidge", "version": "4" }
Url has no mention of Smidge datafolder nor version 4 but some obscure /sc/ path. Website does not contain a Smidge folder anywhere.
https://localhost:44388/sc/adf76721.d3aee927.a68a0402.e0339c9d.684cde55.d6cb19f6.01fc5641.634768ce.2d7f96b7.7da9184e.f386f091.css.v1
Also my razor gave runtime errors when using the @Smidge tag helper - doesn't exist, so was forced to use SmidgeHelper
I'm experiencing this exact issue as well, as what @John-Blair has mentioned. I'm using Umbraco 10.4.0 and Smidge 4.2.0.
I've found that with SmidgeHelper.CssHereAsync() setting debug to true has the url forming correctly when setting the RuntimeMinification settings.