I work a lot with legacy website with css files which were shared across many pages which resulted in really bloated stylesheets shipping to browser. I want to do some performance tricks to avoid this and thought about CriticalCSS (extracting critical styles) and PurgeCSS ("tree shaking" from dead styles for template). I plan to do it for each custom template and I need generated HTML which is shipped to browser. The problem is that I need to get these HTMLs during build process so there is no way to do actual request to Wordpress and just get them from output buffer.
So is there a way to get generated page from Wordpress by just running from CLI not by requesting real URL? It would probably be needed to pass post ID or part of URL identifying post as an argument so it could properly setup query.
Solutions I tried:
- PurgeCSS input can analyse PHP files but there is no HTML from Wordpress
specific functions (
- I can get HTML by running WP-CLI command
wp-cli eval-file <template-file>but then all HTML that is depended of queried post is lost (no query setup).
- I have also seen this solution to get HTML but it still needs proper query setup.