-
Notifications
You must be signed in to change notification settings - Fork 164
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
Elements with display: none are considered above the fold #306
Comments
This check is indeed why elements with |
Hi @pocketjoso, thanks for responding. Here are some of my use cases for having HTML elements that are not visible during the initial render:
While some websites do use JS for rendering content (React, Vue etc.), I believe a lot of websites also simply follow the separation of concerns principle by keeping all content in the HTML and using JS / CSS for tweaking availability by adding/removing classes, styles or attributes. We certainly do that.
This is a valid suggestion. However, given that Penthouse is a library for general usage and does not come with prescriptions about markup style, it might be worth accommodating for the reality that web pages do contain elements with
How about checking for a |
Thanks for the follow up and the use cases you presented.
The problem is that we cannot discern whether an element is in view or not just by the fact that the bbox call yields Penthouse would have to unset some applied styles, or start using IntersectionObserver instead. In either case this would require some work and decent amount of testing to ensure it doesn't slow down the critical css generation too much - given that Penthouse iterates over a very high number of elements. Given the amount of work for the relatively small return (pruning styles for non critical display:none elements), I don't think I will get around to this anytime soon. If you're interested though, feel free to open a PR! |
We would also benefit from display:none elements being removed. In our scenario, we've got a 'mega nav' where the navigation is all loaded in the initial page load, and is beneficial for SEO. The nav is display:none at the start until the burger icon is clicked,, but there are a lot of classes and CSS that could be removed from the critical CSS. For now, we can just add lots of ignore rules, or change our CSS from being display;none to something like position:absolute; top:99999px; visibility:hidden; etc |
Thanks for the info. I will look into it eventually, but not likely in the short term. |
I’m facing an issue where elements that have
display: none
applied on them are considered above the fold and in the critical path, resulting in the inclusion of all their CSS styles. For example, I have a<button class="example">
in my footer which is hidden by default and may optionally be made visible by JavaScript. This is resulting in CSS forbutton
and.example
etc. to be included.Looked around the code and I suspect this happens because
getBoundingClientRect
returns thetop
value as0
for hidden elements, falsely giving the impression that they are visible above the fold.penthouse/src/browser-sandbox/pruneNonCriticalSelectors.js
Line 25 in e61253e
The text was updated successfully, but these errors were encountered: