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

"save-used" for style images and fonts missing resources referred via a CSS variable #145

Open
danny0838 opened this issue Mar 21, 2020 · 0 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@danny0838
Copy link
Owner

It's currently extremely hard to detect whether a font or a style image is actually used if it is referred indirectly via a CSS variable.

For a simple case like:

:root { --var-1: url("var1.bmp"); }
#var1 { background: var(--var-1); }

will work in many cases, as WSB assumes any URL used by a none selector pseudoclass as used.

There is not luck for more complicated cases, though:

@font-face { font-family: var2; src: url("var2.woff"); }
:root { --var-2: var2; }
#var2 { font: 1.1em var(--var-2); }
@keyframes var3 {
  from { background-image: url("var3.bmp"); }
  to { transform: translateX(40px); }
}
:root { --var-3: var3; }
#var3 { animation: var(--var-3) 3s linear infinite; }

In such cases an element has refers to a CSS variable which points to a keyframes or font, causing WSB failed to detect whether the keyframes or font is used, and the resources used by them are thus considered (incorrectly) as unused and not captured.

It is currently very hard to trace the cascaded CSS value of a CSS variable. For example, the value of a CSS variable --var-3 referred by a html > body > div#var3 element can be taken from #var3, div, or even inherted from an ancestor such as body, html, *, or :root.

Reading the computedStyle also don't work as the computed value can be changing if there's an animation. In the above example, the computedStyle of background-image of #var3 toggles between url(".../var3.bmp") and none over time.

Furthermore, resolving the absolute URL for a CSS variable is also difficult. In the above example, the resolved URL of --var-3 whose value is url("var3.bmp") can vary, depending on the stylesheet or document where var(--var-3) is used.

@danny0838 danny0838 added bug Something isn't working help wanted Extra attention is needed labels Mar 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant