Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whilst I can get filewatching for JS to work happily, same settings for CSS isn't working? #206

Open
mistyn8 opened this issue Apr 5, 2024 · 9 comments

Comments

@mistyn8
Copy link

mistyn8 commented Apr 5, 2024

Cloning the project

and updating Startup.cs with

bundles.CreateJs("test-bundle-2", "~/Js/Bundle2")
    .WithEnvironmentOptions(BundleEnvironmentOptions.Create()
            .ForDebug(builder => builder
                //.EnableCompositeProcessing()
                .EnableFileWatcher()
                .SetCacheBusterType<AppDomainLifetimeCacheBuster>()
                .CacheControlOptions(enableEtag: false, cacheControlMaxAge: 0))
            .ForProduction(builder => builder
                .EnableCompositeProcessing()
                .EnableFileWatcher()
                .SetCacheBusterType<AppDomainLifetimeCacheBuster>()
                .CacheControlOptions(enableEtag: false, cacheControlMaxAge: 0))
            .Build()
    );

bundles.CreateCss("test-bundle-css", "~/css/Bundle1")
   .WithEnvironmentOptions(BundleEnvironmentOptions.Create()
           .ForDebug(builder => builder
               .EnableCompositeProcessing()
               .EnableFileWatcher()
               .SetCacheBusterType<AppDomainLifetimeCacheBuster>()
               .CacheControlOptions(enableEtag: false, cacheControlMaxAge: 0))
           .ForProduction(builder => builder
               .EnableCompositeProcessing()
               .EnableFileWatcher()
               .SetCacheBusterType<AppDomainLifetimeCacheBuster>()
               .CacheControlOptions(enableEtag: false, cacheControlMaxAge: 0))
           .Build()
   );

If I change js\bundle2\b2.js on a subsequent refresh of the page the message written out is updated.
However, changing /css/Bundle1/a2.css on refresh the cache has not been busted?

Is EnableFileWatcher() not available for css?

@mistyn8
Copy link
Author

mistyn8 commented Apr 5, 2024

my bad.. was a css cascading issue... removed all but my cssHereAsync and works as expected.

@mistyn8 mistyn8 closed this as completed Apr 5, 2024
@mistyn8 mistyn8 reopened this Apr 5, 2024
@mistyn8
Copy link
Author

mistyn8 commented Apr 5, 2024

So native smidge works.. but in umbraco.. filewatcher seems to not work at all..
Even reverting to the native ConfigCacheBuster, the appended version with filewatcher is v1..

private readonly IBundleManager _bundles;
...
 _bundles.CreateCss("test-bundle-2", "~/css/custom.css", "~/css/ig-theme.defaults.css")
    .WithEnvironmentOptions(BundleEnvironmentOptions.Create()
            .ForDebug(builder => builder
                .EnableCompositeProcessing()
                .EnableFileWatcher()
                .SetCacheBusterType<ConfigCacheBuster>()
                .CacheControlOptions(enableEtag: false, cacheControlMaxAge: 0))
            .ForProduction(builder => builder
                .EnableCompositeProcessing()
                .EnableFileWatcher()
                .SetCacheBusterType<ConfigCacheBuster>()
                .CacheControlOptions(enableEtag: false, cacheControlMaxAge: 0))
            .Build()
    );

@Shazwazza any pointers?

Umbraco 13.2.0 + Smidge 4.2.0... looks like they are messing about with smidge, as the urls aren't ending with .css

Generated named-bundled JS Urls
        /sb/igloo-js-bundle.js.v1
        /App_Plugins/uSync/usync.13.1.1.min.css?v=638479276611835589
        /sb/umbraco-preview-js.js.v638479276611835589
        /sb/umbraco-backoffice-extensions-js.js.v638479276611835589
        /sb/usync%20history-js.js.v638479276611835589
        /sb/umbraco-backoffice-js.js.v638479276611835589
        /App_Plugins/uSync/usync.13.1.1.min.js?v=638479276611835589
        /sb/umbraco-tinymce-js.js.v638479276611835589
Generated named-bundled CSS Urls
        /sb/test-bundle-2.css.v1
        /sb/umbraco-authorize-upgrade-css.css.v638479276611835589
        /sb/umbraco-preview-css.css.v638479276611835589
        /sb/umbraco-backoffice-init-css.css.v638479276611835589
        /sb/igloo-css-bundle.css.v638479276611835589
        /sb/umbraco-backoffice-css.css.v638479276611835589

@Shazwazza
Copy link
Owner

In Umbraco, the backoffice Smidge implementation is entirely separate from the native (front-end) Smidge usage (if you want to use it). This is intentional so that the back office Smidge config and implementation doesn't affect how normal Smidge would execute on your front-end.

This is why there is separate configuration for this specific to Umbraco (back office) https://docs.umbraco.com/umbraco-cms/reference/configuration/runtimeminificationsettings.

You might try looking here https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Web.Common/RuntimeMinification/SmidgeRuntimeMinifier.cs

@mistyn8
Copy link
Author

mistyn8 commented Apr 5, 2024

yep.. though also tried overriding the builder...

public class BundleComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        builder.Services.Configure<SmidgeOptions>(options =>
        {
            options.DefaultBundleOptions.ProductionOptions.FileWatchOptions.Enabled = true;
            options.DefaultBundleOptions.DebugOptions.FileWatchOptions.Enabled = true;
            //options.DefaultBundleOptions.ProductionOptions.SetCacheBusterType<AppDomainLifetimeCacheBuster>();
            //options.DefaultBundleOptions.ProductionOptions.CacheControlOptions.CacheControlMaxAge = 12000;
        });
    }
}

And still no cache busting on fileWatching :-(

@mistyn8
Copy link
Author

mistyn8 commented Apr 5, 2024

Is it also not odd that setting

  "smidge": {
    "dataFolder": "Smidge", //where the cache files are stored
    "version": "125", //can be any string
}

isn't respected by the native ConfigCacheBuster over the UmbracoSmidgeConfigCacheBuster ??

@Shazwazza
Copy link
Owner

Is this for your front-end or back-end, again, they operate independently. I haven't looked at this integration for many years so unfortunately I can't pinpoint what you need to do.

@mistyn8
Copy link
Author

mistyn8 commented Apr 5, 2024

It is for my frontend (though just the umbraco mvc and not a headless implementation)

Can I have a native smidge implementation for the front end? and leave the backoffice to be umbraco runtimeMinification?

As seems to be overlapping eg smidgehelper gets backoffice settings? Although you are saying that I should be able to have an independent setup??

I'm guessing that they can't be truly independent as you'd not be able to avoid bundle named collisions?

eg I can't have Services.AddSmidge() twice in the same app?

@mistyn8
Copy link
Author

mistyn8 commented Apr 5, 2024

guessing this might be in the mix.. lots of alter smidge to umbraco requirements...
https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs#L291-L321

 public static IUmbracoBuilder AddRuntimeMinifier(this IUmbracoBuilder builder)
    {
        // Add custom ISmidgeFileProvider to include the additional App_Plugins location
        // to load assets from.
        builder.Services.AddSingleton<ISmidgeFileProvider>(f =>
        {
            IWebHostEnvironment hostEnv = f.GetRequiredService<IWebHostEnvironment>();

            return new SmidgeFileProvider(
                hostEnv.WebRootFileProvider,
                new GlobPatternFilterFileProvider(
                    hostEnv.ContentRootFileProvider,
                    // only include js or css files within App_Plugins
                    new[] { "/App_Plugins/**/*.js", "/App_Plugins/**/*.css" }));
        });

        builder.Services.AddUnique<ICacheBuster, UmbracoSmidgeConfigCacheBuster>();
        builder.Services.AddSmidge(builder.Config.GetSection(Constants.Configuration.ConfigRuntimeMinification));

        // Replace the Smidge request helper, in order to discourage the use of brotli since it's super slow
        builder.Services.AddUnique<IRequestHelper, SmidgeRequestHelper>();
        builder.Services.AddSmidgeNuglify();
        builder.Services.AddSmidgeInMemory(false); // it will be enabled based on config/cachebuster

        builder.Services.AddUnique<IRuntimeMinifier, SmidgeRuntimeMinifier>();
        builder.Services.AddSingleton<SmidgeHelperAccessor>();
        builder.Services.AddTransient<IPreProcessor, SmidgeNuglifyJs>();
        builder.Services.ConfigureOptions<SmidgeOptionsSetup>();

        return builder;
    }

@mistyn8
Copy link
Author

mistyn8 commented Apr 5, 2024

Is it that I need to extend the Smidge FileSystem to allow watching, although my files are in the wwwroot/css/ folder anyway?

https://github.com/Shazwazza/Smidge/blob/develop/src/Smidge/SmidgeStartup.cs#L156

                foreach (var webFileType in new[] { WebFileType.Css, WebFileType.Js })
                {
                    var bundles = bundleManager.GetBundles(webFileType);
                    foreach (var bundle in bundles)
                    {
                        WireUpFileWatchEventHandlers(cacheBusterResolver, fileSystem, bundle);
                    }
                }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants