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

Style not using cdn_src even if CDN is enabled #11153

Open
DemeSzabolcs opened this issue Feb 9, 2022 · 6 comments
Open

Style not using cdn_src even if CDN is enabled #11153

DemeSzabolcs opened this issue Feb 9, 2022 · 6 comments
Labels
Milestone

Comments

@DemeSzabolcs
Copy link
Contributor

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
Copy link
Contributor

Skrypt commented Feb 10, 2022

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

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
Copy link
Member

Piedone commented Feb 10, 2022

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 #11154.

@sebastienros
Copy link
Member

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
Copy link
Member

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

@sebastienros
Copy link
Member

The 'name' triggers the behavior, otherwise it's just a <style> tag without custom logic from our side.

@Skrypt
Copy link
Contributor

Skrypt commented Feb 10, 2022

The only logic required is to use either an src, debug_src, cdn_src, cdn_debug_src attribute on the tag based on the CDN settings applied on the tenant.

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

No branches or pull requests

4 participants