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:

  1. PurgeCSS input can analyse PHP files but there is no HTML from Wordpress specific functions (get_header(), get_footer()).
  2. 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).
  3. I have also seen this solution to get HTML but it still needs proper query setup.


  • 1
    Maybe I didn't understand your technical limitations correctly, but is there a problem with fetching the html through a bash command (be it wget, curl or whatever is available to the hosting enviornment) and then work with it?
    – vlood
    Commented Aug 25, 2021 at 8:15
  • Current deployment setup uses Atomic Deployments so after repo clone, successful frontend build, database swap etc. symlink to the just built project directory is changed and then website may be accessed via url. I would need to fetch html after that symlink change and I wanted to avoid it and do it somewhat during frontend built.
    – jamkaka
    Commented Aug 28, 2021 at 8:43


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.