I notice the buttons on my page flickering when I hover on it (will change opacity). After some digging, it turns out the browser re-downloads that image every time the style updates.
This happens on Mac Chrome 74, and Safari. Firefox seems fine.
The buttons is styled using background-image with CSS variables, the code looks like this:
body {
--src-image: url("some image");
}
.btn {
background-image: var(--src-image);
}
.btn:hover {
opacity: 0.7;
}
Codepen: https://codepen.io/polyamide/pen/qzEVzO
Repro steps:
- Open DevTool and disable cache.
- Hover on and off on the second image (this one using CSS variable, while the first one is not).
- See network panel. There will be a new request when the style updates.
Avoid using css variable solves the problem, but I still want to understand why is this happening, and how can I fix it?