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

"AppDomain" cachebuster still uses the value of "Version" in it's generated URLs. #15165

Open
shropgov-neil opened this issue Nov 8, 2023 · 15 comments
Labels
affected/v10 affected/v12 state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks type/bug

Comments

@shropgov-neil
Copy link

shropgov-neil commented Nov 8, 2023

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

12.3.1

Bug summary

The generated URL for a Smidge bundle will always use the "Umbraco.CMS.RuntimeMinification.Version" value, regardless of the value of "Umbraco.CMS.RuntimeMinification.CacheBuster".

Specifics

I've had an ongoing issue since v10 where all my bundles are generated with the URL "/sb/{bundle}.v1.{css/js}", despite "CacheBuster" being set to "AppDomain" - the only way to change "v1" is to set the "Umbraco.CMS.RuntimeMinification.Version" value manually.

We do not want to be setting the version string manually, but need the URL to change on each deploy to avoid browsers aggressivly caching out of date assets.

It doesn't matter what value I set "CacheBuster" to (AppDomain or Timestamp), the version value will always be the value of "Version" (or "v1", if you leave it blank).

This happens in both Debug and Production, and the values of "Umbraco.CMS.RuntimeMinification.UseInMemoryCache" and "Umbraco.CMS.RuntimeMinification.KeepFileExtensions" do not make a difference.

Steps to reproduce

Create a custom Smidge bundle (with SmidgeHelper.Create{Js/Css}Bundle()), add at least one file to the bundle (with Require{Js/Css}()).

Set "Umbraco.CMS.RuntimeMinification.CacheBuster" to "AppDomain".
Do not set a value for ""Umbraco.CMS.RuntimeMinification.Version".

Render the reference with one of the SmidgeLinkTagHelper / SmidgeScriptTagHelper, with debug set to false.

Check the href/src value outputted in the source code.

Try setting a value of Version (while keeping it set to "AppDomain"), and check the source again.

Expected result / actual result

I would expect to see a unique filename for every cycle of the AppPool, what I actually see is "style.v1.css" every single time (or whatever the value of "Version" is).


This item has been added to our backlog AB#35172

Copy link

github-actions bot commented Nov 8, 2023

Hi there @shropgov-neil!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

  • We'll assess whether this issue relates to something that has already been fixed in a later version of the release that it has been raised for.
  • If it's a bug, is it related to a release that we are actively supporting or is it related to a release that's in the end-of-life or security-only phase?
  • We'll replicate the issue to ensure that the problem is as described.
  • We'll decide whether the behavior is an issue or if the behavior is intended.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@shropgov-neil
Copy link
Author

shropgov-neil commented Nov 8, 2023

I've done some more digging and it appears it's something to do with not passing the configuration options to the native smidge functions - so the built in SmidgeHelper isn't using them.

I trawled the source code and found an undocumented Umbraco.Cms.Web.Common.RuntimeMinification.SmidgeRuntimeMinifier which re-implements CreateCssBundle and CreateJsBundle for the back office - if I inject this into my view and use those functions, the files are generated with the correct AppDomain cachebuster. This then works for the first page load, but subsequent page loads crash with "The bundle name {bundle} already exists" which persists until the cache is cleared.

Can we either get the config options passed to the native functions, or (if this is the supported way to do it) get the SmidgeRuntimeMinifier method documented somewhere?

@dhymik
Copy link

dhymik commented Nov 17, 2023

Thank you for raising this issue. I was pulling my hair out about this myself as well. I hope this can be fixed soon.

@shropgov-neil
Copy link
Author

If it helps, as a workaround I created my own service, injected IRuntimeMinifier and IBundleManager so that I could overload the functions to check the bundles didn't already exist before creating them. Then just injected that into my view to keep that cleaner.

Seems awfully hacky, but it works until a proper documented resolution is provided.

@shropgov-neil
Copy link
Author

A slightly better, but no less hacky fix was to go back to using the proper SmidgeHelper class, but with this in Startup.cs

  services.Configure<SmidgeOptions>(options =>
      {
        string cachebuster = _config.GetSection("Umbraco:CMS:RuntimeMinification").GetValue<string>("CacheBuster") ?? "AppDomain";
        Type cacheBusterType = Enum.Parse<RuntimeMinificationCacheBuster>(cachebuster) switch
        {
          RuntimeMinificationCacheBuster.AppDomain => typeof(AppDomainLifetimeCacheBuster),
          RuntimeMinificationCacheBuster.Version => typeof(ConfigCacheBuster),
          RuntimeMinificationCacheBuster.Timestamp => typeof(TimestampCacheBuster),
          _ => throw new NotImplementedException(),
        };

        options.DefaultBundleOptions.DebugOptions.FileWatchOptions.Enabled = true;
        options.DefaultBundleOptions.DebugOptions.SetCacheBusterType(cacheBusterType);
        options.DefaultBundleOptions.ProductionOptions.SetCacheBusterType(cacheBusterType);
        options.DefaultBundleOptions.ProductionOptions.ProcessAsCompositeFile = true;
      });

Hope that helps someone while we wait for an official answer.

@Migaroez
Copy link
Contributor

  • verified on v10 and v12
  • version number stays the same when using AppDomain cachebuster
  • doesn't matter if you use the smidge taghelper or the umbraco generic wrapper
<link rel="stylesheet" href="pageBundle" debug="false"/>
@Html.Raw(await runtimeMinifier.RenderCssHereAsync("pageBundle"))

@Migaroez Migaroez added state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks affected/v10 affected/v12 labels Nov 20, 2023
@nhaberl
Copy link

nhaberl commented Jan 23, 2024

Any news here ?

@thenexus00
Copy link

Hi, Also not seeing caching being updated when "AppDomain" set and restarting an application pool.

Copy link

azure-boards bot commented Feb 8, 2024

❌ There was a problem linking to Azure Boards work item(s):

  • 35172

Please check the IDs and try again using the AB# syntax. Learn more

4 similar comments
Copy link

azure-boards bot commented Feb 8, 2024

❌ There was a problem linking to Azure Boards work item(s):

  • 35172

Please check the IDs and try again using the AB# syntax. Learn more

Copy link

azure-boards bot commented Feb 8, 2024

❌ There was a problem linking to Azure Boards work item(s):

  • 35172

Please check the IDs and try again using the AB# syntax. Learn more

Copy link

azure-boards bot commented Feb 8, 2024

❌ There was a problem linking to Azure Boards work item(s):

  • 35172

Please check the IDs and try again using the AB# syntax. Learn more

Copy link

azure-boards bot commented Feb 8, 2024

❌ There was a problem linking to Azure Boards work item(s):

  • 35172

Please check the IDs and try again using the AB# syntax. Learn more

@shropgov-neil
Copy link
Author

@UmbracoHQ Can someone pelase disable the azure-boards bot (or fix the issue) so we're not getting spammed hourly?

@kikodev714
Copy link

A slightly better, but no less hacky fix was to go back to using the proper SmidgeHelper class, but with this in Startup.cs

  services.Configure<SmidgeOptions>(options =>
      {
        string cachebuster = _config.GetSection("Umbraco:CMS:RuntimeMinification").GetValue<string>("CacheBuster") ?? "AppDomain";
        Type cacheBusterType = Enum.Parse<RuntimeMinificationCacheBuster>(cachebuster) switch
        {
          RuntimeMinificationCacheBuster.AppDomain => typeof(AppDomainLifetimeCacheBuster),
          RuntimeMinificationCacheBuster.Version => typeof(ConfigCacheBuster),
          RuntimeMinificationCacheBuster.Timestamp => typeof(TimestampCacheBuster),
          _ => throw new NotImplementedException(),
        };

        options.DefaultBundleOptions.DebugOptions.FileWatchOptions.Enabled = true;
        options.DefaultBundleOptions.DebugOptions.SetCacheBusterType(cacheBusterType);
        options.DefaultBundleOptions.ProductionOptions.SetCacheBusterType(cacheBusterType);
        options.DefaultBundleOptions.ProductionOptions.ProcessAsCompositeFile = true;
      });

Hope that helps someone while we wait for an official answer.

This code helped me. Thanks! I'm actually using "Version" mode but I'm wondering if there's also a way I could also influence the version number instead of using what's in the appConfig. I'm trying to obtain it from a SharedAssembly class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affected/v10 affected/v12 state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks type/bug
Projects
None yet
Development

No branches or pull requests

6 participants