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
Ability to ignore js script in html #321
Comments
There's no way to ignore it, other than commenting it out AFAIK. Personally, I'd just switch to |
@RyanZim I agree that nowadays it is safe to switch to |
@armpogart We're using jsdom under the hood, so I'm not sure how this would be possible. |
@RyanZim Does uncss give a way to configure jsdom as it had skipExternalResources property in old api which is still supported (as stated in their main documentation). If so we could give it regex and document the ability to ignore unneeded resources. |
Why not delete it in the source html file, before you pass it to uncss?
Most people have to do some kind of template production to pass valid full
html files to uncss, so just extend that process...? (Post process deletion
via awk/whatever, or configure templates to omit analytics in the html
production, etc)
2017年7月14日(金) 11:25 Arman Poghosyan <notifications@github.com>:
… @RyanZim <https://github.com/ryanzim> Does uncss give a way to configure
jsdom as it had skipExternalResources
<https://github.com/tmpvar/jsdom/blob/master/lib/old-api.md#external-resources>
property in old api which is still supported (as stated in their main
documentation). If so we could give it regex and document the ability to
ignore unneeded resources.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#321 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AHlba0iKu5SRjkXzDhOhyPxzWLfOJSxUks5sN4iAgaJpZM4OYVTH>
.
|
This will break many projects that still use protocol relative URLs. Isn't there any way to ignore specific HTML from being parsed? |
IIRC, uncss continues despite this error, the script just isn't loaded. PhantomJS had the same issue, it just was too opaque to report the error. You're going to have the exact same problem if you open a local html file with a normal web browser. One possible workaround is to run a small http server, and run uncss on |
I still think the problem is not only on loading relative url. Why to load it in the first place, there can be many scripts that are there for other purposes and we don't need to load them (parse them) during uncss. So I still think it would be valid feature to have a way to ignore it. |
Thinking a bit more about this, perhaps we could have a script blacklist implemented in the resource loader. |
The most prominent issue with that — it isn't always possible. A lot of 3rd-party scripts will load their own dependencies and additional files. You might need part of them, but the other half will yield those errors, or load something you didn't want to, at least affecting badly performance. Besides, with large amount of pages there is an issue with loading remote resources that you don't want — they start to fail (for instance, not all servers like 300 requests in a row), and this might lead to erroring in resources that you really wanted. But because my statement above, simple deletion of remote resources would not always solve the problem. Here said that Also, here jsdom/jsdom#1567 said that another way is to use custom resource loader, though, I'm not aware how more difficult it is. |
We're already using a custom resource loader; we just need to add this feature to our custom loader. |
That would be really great |
I use a templating system and I have this line in my HTML template <script src="{applicationPath}/assets/scripts.2.5.0.js"></script> I was using UnCSS 0.14.1 before, and it had no problems. Now on 0.15.0 is produces this error: Which then produces this error
For now my workaround is to remain on the older version so I can have my project continue to work. |
Previously, the failure-to-load-js error was hidden. Now the error is shown. Note that the previous version did not load the js-at-all, and so any CSS classes, or HTML elements, that were constructed by that JS would not have been seen by UnCSS. My recommendation (what I do in my own project), is to generate fully-formed HTML pages from your server/code, and then run those through UnCSS, where you can verify they are proper HTML and not just "templates". |
That's not possible with my project, so I guess I'm either stuck waiting on the ability to blacklist certain scripts , disable all scripts, suppress errors, or just stick with the older version. |
I tried to use the '-t 0' flag to get uncss NOT to try to load any JS. May be worth using that as an official way of disabling load and run of JS. I don't touch any CSS in my JS, and almost all my JS is AdSense which I'd prefer that uncss didn't even try to run. Indeed I get errors from the protocol-relative code recommended by Google, and which one is not meant to edit according Google's Ts&Cs. Maybe I'll fall back to purifycss for files with embedded scripts to avoid the errors at the cost of some extra bloat... Rgds Damon |
I do have the same problem as chrismbarr. I have a template directory, path to js-scripts look like this (NEOS CMS):
Alternatively, I tried to provide the test page, which has proper HTML. However, looks like I use some script that is understood by modern browsers but not by jsdom, resulting in this error:
|
jsdom doesn't support |
That error is easy to bypass by doing something like if (window.matchMedia) {
// your code goes here
} Then it will be simply ignored by jsdom. |
+1 for a script blacklist option. That would be really useful. |
Any updates to this? |
Hey, Wanted to clarify, as of today, is there a way to turn it off with |
Confirming that minification still occurs despite the error. But would be nice to somehow suppress it. |
I have following js snippet for Google Analytics at the end of my html file:
and uncss tries to load that js file, which it couldn't as you can see there is no protocol specified there, and even if there's protocol there, I don't see a reason to parse Google Analytics JS for uncss. So the question: is there a way (some uncss specific comment) to ignore that js script.
The stack trace is:
The text was updated successfully, but these errors were encountered: