-
Notifications
You must be signed in to change notification settings - Fork 35
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
Puppeteer Page Event - 'domcontentloaded', 'load', 'networkidle0', 'networkidle2' #205
Comments
So your only concern is what event used to detect finish of load e.g 'domcontentloaded' vs 'load' vs 'networkidle0' vs 'networkidle2' etc. Or you also asking for additional features like ("Make sure this is added to a style tag in the head somehow."). I would suggest to separate different requests in different tickets. About additional feature - there can be another software which can do this based on minimalcss, for example react-snap does it. It is out of scope of current project. About which event to use. It depends on situation, there are situations which require 'networkidle0', but I guess this it can be configurable (not sure if config exposed or not) |
Yes, sorry about the post, it was more of a general discussion than it should have been. I guess the basic question is: when would you need to wait for any event other than 'domcontentloaded' in order to get the styles for any given page? |
We (@stereobooster and I) debated this a lot in the past and concluded that the best thing is to just wait for The reason being is many sites have some $(function() {
// As soon as the page has loaded, extract all <h2> and <h3> tags and
// generate a cute little Table of Contents near the top of the page.
buildAndInsertTableOfContents($('.document h2, .document .h3'), $('.document .toc'));
}); That's just DOM manipulations and doesn't depend on the network. In the example, if the Table of Contents depends on some like Another common thing is that on // React example
componentDidMount {
// Now that the page has rendered, download the related
// news (which is less critical) and display in the side-bar.
fetch('/api/related-news').then(r => r.json())
.then(news => this.setState({relatedNews: news}))
}; In both of these examples, by using It's just safer that way. If we try to extract minimalcss earlier, what MIGHT happen is that (as the per last example above) the related news is displayed in the side-bar without nice styling. We recommended that you replace the render blocking CSS with the minimal/critical CSS but still load the rest of all the CSS later. |
Suppose that the DOM changes a bunch between |
Note that there's another interesting thing. There is a time between <div class="toc toc-pending">Table on contents will be inserted here</div> ...together with... .toc-pending {
opacity: 0.7;
color: #efefef;
} And the $(function() {
// As soon as the page has loaded, extract all <h2> and <h3> tags and
// generate a cute little Table of Contents near the top of the page.
buildAndInsertTableOfContents($('.document h2, .document .h3'), $('.document .toc'));
$('.document .toc').removeClass('toc-pending');
}); I.e. the DOM might look/styled a certain way that only lasts a couple of hundred milliseconds whilst the user is waiting for the lazy-loaded We're deliberately missing that opportunity. I.e. |
OK. The reason I asked these questions is that I have done a lot of testing of Puppeteer in the wild and the |
Totally a valid point. One argument that was made previously is that if you're so performance-hungry that you even use a tool like this you probably don't have a bunch of weird requests that timeout. You're likely to have bigger problems. But we can wait and see. If the above statement is wrong, we could consider an option where you can actually control the thing to waitfor. E.g. "I really know what I'm doing and I know that only junk, that don't affect the first-render CSS, is going to time out." |
Should we close this as non-actionable ticket? |
Hey,
I've had a look at the code you're using to extract the styles (run.js) and I have a question / comment.
My understanding is that CSS styling tends to be render-blocking, whether it is in the form of a style tag, a link to an external style sheet, or inline styling on an element.
There is of course additional styling done by Javascript as and when that loads, whether it be render-blocking or async / defer.
From a performance point of view, there are two things that could usefully be done by a minimal css project. Firstly, identify the minimal css required above the fold to make sure that the first paint is properly styled. Make sure this is added to a style tag in the head somehow. Secondly, make sure that the total volume of css is only that required by the page, i.e. remove redundant selectors and their respective css rules from the download package.
Now, it seems to me that both the above could be achieved by waiting only for the 'domcontentloaded' event in Puppeteer. This event is quicker and more reliable in the wild than the 'load' event and the two 'networkidle' events. By definition, you can then use
response.text()
on a external stylesheet response to get all the rules andpage.$$eval
to assess those rules.Seems to me to be a quicker and more reliable way to get the above-the-fold and present/not present elements and then divide the styling accordingly. Any styling applied by Javascript can be ignored.
The text was updated successfully, but these errors were encountered: