News for hackers. Stuff that matters.
Re:CSSnano by stigok on Monday September 16, 2024 @04:47AM (#41554055)
This would work nicely with static HTML, indeed. But once you have some JavaScript i.e. dynamic HTML, it won't work reliably anymore. Worse, it might even give you a list of manually curated CSS properties to "allow list".
Re:CSSnano by merb on Monday September 16, 2024 @08:59AM (#41555622)
this is incorrect.

the only thing that does not work is generating the css class like:

var x = 'hase-';

var t = x + 'danger'

which is an antipattern. (it can even happen inside java, c#, whatever language you use and it is still an antipattern)

Re:CSSnano by phito on Monday September 16, 2024 @09:47AM (#41556034)
Can you please elaborate why it is an antipattern? I'm not sure I understand.
Re:CSSnano by sionisrecur on Monday September 16, 2024 @12:15PM (#41557615)
At least regarding tailwindcss, it checks your code to filter out unused css classes. So it is recommended to have full class names in the code instead of constructing them by concatenating strings. So if you have a variable `buttonColor` that can be `red` or `blue` it is better to do something like

    switch(buttonColor) {
        'red': return 'button-red';
        'blue': return 'button-blue';
    }
over

    return 'button-' + buttonColor;
Re:CSSnano by merb on Monday September 16, 2024 @01:25PM (#41558345)
if you are in a big project and want to refactor classes the string concatenation pattern gets extremely painful, it’s even worse when it’s done on the server and on the frontend. At some point you will have trouble removing your classes. My company did this a lot and know we struggle to clean it up since basically all classes are used somewhere. What we do is basically use purgecss and than diff it and look for all occurrences that got removed which will take us a few months.
Re:CSSnano by phito on Tuesday September 17, 2024 @04:17AM (#41565532)
Oh ok it was about concatenation, not just this example case. Got it, thank you!
Re:CSSnano by Izkata on Monday September 16, 2024 @11:44AM (#41557234)
Waaay back there used to be a Firebug plugin that would monitor which CSS was ever used as you interacted with a page. Worked great for exactly these dynamic pages - I was using it with React for a few years before Quantum killed the XUL addons.

I'd forgotten about it and am now wondering if anyone made a replacement...

Re:CSSnano by Ayesh on Monday September 16, 2024 @12:24PM (#41557725)
Chrome Dev tools has this feature. It's not as useful because when you navigate to another page, it resets the used CSS rules.