OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.42k stars 2.39k forks source link

Style not using cdn_src even if CDN is enabled #11153

Open DemeSzabolcs opened 2 years ago

DemeSzabolcs commented 2 years ago

Describe the bug

I wanted to use a local source and a CDN source for a CSS in a Layout.liquid file. See:

{% style src:"~/example/css/example.css",
                cdn_src:"https://example.com/css/example.css" %}

I turned on CDN inside Configuration -> Settings -> General -> Resources, but it still used the local source (~/example/css/example.css). I also tried enabling and disabling Resource Debug Mode under Configuration -> Settings -> General -> Resources, and enabling and disabling Cache Mode under Configuration -> Settings -> General -> Cache and it didn't work. I set the use_cdn attribute to true inside the style but, it didn't work either. style is always using the resource in src instead of the resource in cdn_src even when CDN is enabled.

To Reproduce

Steps to reproduce the behavior:

  1. Add a style to a .liquid file, e.g Layout.liquid.
  2. Add the src attribute to the style that's value points to a local CSS file.
  3. Add the cdn_src attribute to the style that's value points to an external CSS file.
  4. Go to Configuration -> Settings -> General -> Resources and enable CDN, aka Use framework CDN (Content Delivery Network).
  5. Load a page that uses the .liquid file with the style, and see that the page is using the local resource.

Expected behavior

When CDN is enabled, style should use the resource given in the cdn_src attribute instead of the resource given in the src attribute.

Skrypt commented 2 years ago

If you look at this line and analyze the code of that class.

https://github.com/OrchardCMS/OrchardCore/blob/39b10dae7ae5e38818c6376f273bcaf137c1433f/src/OrchardCore.Modules/OrchardCore.Resources/Liquid/StyleTag.cs#L198

You will see that it should work if you provide a "name" to your style resource.

{% style name:"example", src:"~/example/css/example.css",
                cdn_src:"https://example.com/css/example.css" %}

Question is, should we make it work also without a "name" attribute. Maybe it is by design. Take a look and let us know.

Piedone commented 2 years ago

Hmm, I think when the name is missing, we could generate one based on one of the URLs. Or if it's required, then throw an exception.

For now, I'll add an emphasis for it being required under https://github.com/OrchardCMS/OrchardCore/pull/11154.

sebastienros commented 2 years ago

I believe the razor tag helper handles this case. But if not then it's probably on purpose and we shouldn't change it.

sebastienros commented 2 years ago

It's called an "inline" script/style definition (in case it's mentioned in the code).

sebastienros commented 2 years ago

The 'name' triggers the behavior, otherwise it's just a