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

What about css class dynamically added by some javascript ? #5

Closed
maiis opened this issue Oct 29, 2013 · 7 comments
Closed

What about css class dynamically added by some javascript ? #5

maiis opened this issue Oct 29, 2013 · 7 comments

Comments

@maiis
Copy link

maiis commented Oct 29, 2013

If in my JS, i have:

$(this).addClass('new-class');

How will it be interpreted by uncss ?

@Tobino
Copy link

Tobino commented Oct 29, 2013

Hi,

Uncss will delete the class from the css file if it's not in the html file.
You can add all the css class in the option ignore, so uncss will not delete it.

options = {
    ignore: ['.new-class', '.created_by_jQuery']
    compress: true,
};

@giakki
Copy link
Member

giakki commented Oct 29, 2013

As @Tobino said, for now you can use the ignore option.
The integration with PhantomJS is in the works, I might be able to release it this week.

@addyosmani
Copy link
Member

Hey @giakki. Do you know what the status is of the Phantom integration? Thinking about moving it to master in the future?

@giakki
Copy link
Member

giakki commented Dec 11, 2013

Hey! I rewrote it from scratch, and it looks pretty good!
I might be able to merge it by Saturday

@giakki giakki closed this as completed Dec 15, 2013
@josenobile
Copy link

Hello,

Maybe this will look as a support request.

I use jQuery UI (modal), the "dismissable" functionality stopped working. Also this: http://mynameismatthieu.com/WOW/ stopped working.

To find the selectors that are being removed I inspect the HTML elements (Chrome Developer tools) finding the CSS style tab and compare the full CSS against the uncss version. However for this two libraries I was unable to find any difference using this method.

Is there a better way to detect the missing CSS that are affecting the functionality of the website?

@drschwabe
Copy link

drschwabe commented Oct 2, 2017

Just thinking aloud, why not simply to have the option to pass/parse a JS file for any mention of CSS classes ie- make it detect and include the CSS class in this example:

uncss -parseJS 'myscript.js' > styles.css

Where myscript.js has say 300 lines of code, with one such line being:

$('#some-selector').addClass('.my-cool-class')

and as such, .my-cool-class is included in the final output styles.css

You wouldn't need any JS logic specifically; just cross reference any ".class-names" with what is in the source CSS files and if there is a match include it; otherwise don't include it; ie- it's not CSS; avoid false negatives

@RyanZim
Copy link
Member

RyanZim commented Oct 2, 2017

@drschwabe That's easier said than done without any false positives. https://github.com/purifycss/purifycss does something similar to this.

Locking to avoid further noise on this thread, notifying all the earlier participants.

@uncss uncss locked and limited conversation to collaborators Oct 2, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants