Critical CSS is the small part of your CSS that is needed to draw the first screen of a page. Powered Cache Premium generates it for each type of page, places it directly in the page head, and loads your full stylesheets without blocking. Visitors see a styled page sooner, which improves First Contentful Paint and Largest Contentful Paint.
Available in: Powered Cache Premium, with an active license
Where to find it: Powered Cache → File Optimization → CSS
Requires: a connection from your server to the Powered Cache CSS service, and the ability of your site to load its own pages.
How Critical CSS works #
Critical CSS is generated per template, not per URL. Powered Cache picks sample pages for each template:
- the front page and the posts page (or the home page when you show latest posts),
- the five latest published posts of each public post type (posts, pages, products and so on),
- up to 20 terms with the most posts for each public taxonomy (categories, tags, product categories and so on),
- every published post with Generate specific Critical CSS checked.
These URLs go into a background queue. For each one, your site loads the page itself without cache or optimizations, collects its HTML and the local stylesheets in the page head (print stylesheets are skipped), and sends them to the Powered Cache Critical CSS service. The service returns the CSS needed for the first screen. Powered Cache saves it in wp-content/cache/critical-css/ and stops at the first successful sample for each template. When the queue is finished, the page cache of the site is cleared so pages are rebuilt with the new CSS.
On the front end, Powered Cache then:
- adds the Critical CSS of the matching template in a
<style id="powered-cache-critical-css">block in the page head, - loads your stylesheets without blocking rendering, with a
<noscript>copy for browsers without JavaScript.
Post type archives, author archives and date archives do not get their own generated CSS. They, and any page whose template has no generated CSS yet, use the Fallback Critical CSS. When Separate Mobile Cache is on, a separate mobile version is generated for each template. Logged-in users always get the normal stylesheets.
Set up Critical CSS #
- Make sure your license is active.
- Go to Powered Cache → File Optimization.
- In the CSS group, turn on Critical CSS.
- Add a few general rules to Fallback Critical CSS (see below). It protects pages that have no generated CSS yet.
- Click Save Settings. Generation starts automatically.
- Watch the Critical CSS card in CSS Optimization Status at the top of the screen until it shows Healthy.
- Check a few pages in a private window. The page source should contain
powered-cache-critical-css.
Default: off. With an active license, Apply Recommended Settings turns on Critical CSS.
Read the CSS Optimization Status #
The CSS Optimization Status panel appears at the top of Powered Cache → File Optimization while Critical CSS or Remove Unused CSS is on. It has one card per service. The Critical CSS card shows:
- Last run, Successful runs and Errors: when the service last ran, and how many pages succeeded or failed since the feature was turned on.
- Queued: pages still waiting or running in the background queue.
- HTTP and CSS size: the service’s last response code and the size of the last generated CSS.
- The last message and the last page URL that was processed.
| State | What it means | What to do |
|---|---|---|
| Waiting for first run | Nothing has been generated yet. | Click Regenerate, or wait if you just saved the setting. |
| Processing | Pages are in the queue, or generation was requested less than two hours ago. The button shows Generating. | Wait. Generation runs in the background, one page at a time. |
| Healthy | The last run succeeded. | Nothing. |
| Needs attention | The last page failed, or generation was requested more than two hours ago without any result. The button shows Retry generation. | Read the message and HTTP code, fix the cause, then click Retry generation. See CSS generation issues. |
| Unavailable | A compatibility safeguard paused the service, for example Disabled to avoid conflicts with Autoptimize. | Review the safeguard. You can pause the source if you are sure there is no conflict. |
The Regenerate button is disabled while a run is in progress, while the setting is off (Enable and save the related setting before regenerating.), or while the service is unavailable. The same results appear in the system check of the Optimization Advisor.
When Critical CSS is regenerated #
A full regeneration removes the site’s existing Critical CSS files and queues all sample pages again. It starts when:
- you turn on Critical CSS and save,
- you change Critical CSS Additional Files or Critical CSS Excluded Files and save,
- you clear all caches (Purge All Cache),
- you switch themes,
- you click Regenerate in the status panel, or Powered Cache → Generate Critical CSS in the admin bar (it opens File Optimization and starts generation there),
- you run the WP-CLI command.
Starting a new run cancels the queue of the previous one. Saving a published post with Generate specific Critical CSS regenerates only that post. Unchecking the option, or unpublishing or deleting the post, removes its specific CSS. Changes to Append to Critical CSS and Fallback Critical CSS apply right away and need no regeneration. While a run is in progress, pages without a generated file use the fallback.
When you turn off Critical CSS and save, Powered Cache cancels all queued jobs, clears the status and deletes the generated files.
New in 4.0: Critical CSS is generated through a background queue with the CSS Optimization Status panel, automatic regeneration when its file settings change, and cancellation when it is turned off. The admin bar’s Generate Critical CSS item now opens File Optimization and starts the run there.
Settings #
The four text fields are shown when Critical CSS is on. All are empty by default.
Critical CSS Additional Files #
Extra stylesheets to include when Critical CSS is generated, one URL per line. Use it for stylesheets that are loaded outside the page head, for example in the footer or by JavaScript, but style the first screen. Only files stored on your own site can be added.
https://example.com/wp-content/themes/my-theme/assets/header.css
Critical CSS Excluded Files #
Stylesheets to leave out of generation, one URL per line. Enter the full stylesheet URL. Each line must point to exactly that file; wildcards and partial matches are not supported here. Exclude a stylesheet when its rules make the Critical CSS too large or pull in styles that do not belong on the first screen. Admin bar, Dashicons, print and wp-admin stylesheets are always left out by the built-in safeguards.
Append to Critical CSS #
CSS that is always added after the Critical CSS on every page, including pages that use the fallback. Use it to fix small layout shifts the generator misses, such as a fixed header height:
.site-header { min-height: 80px; }
Fallback Critical CSS #
CSS used when no generated Critical CSS exists for a page: before the first run finishes, while a run is in progress, and on templates without generated CSS. Because stylesheets are loaded without blocking on every page while Critical CSS is on, a page with neither generated nor fallback CSS can briefly show unstyled content. Add the basic layout rules of your header, navigation and body text here.
Per-page options #
While Critical CSS is on, the Powered Cache panel in the post editor offers two options. Only one of them can be checked at a time.
- Disable Critical CSS for this post: the post gets no Critical CSS and loads its stylesheets normally. Use it when a page looks wrong with Critical CSS.
- Generate specific Critical CSS: Powered Cache generates Critical CSS from this post alone instead of using the shared CSS of its post type. Use it for landing pages or pages with a unique layout. The post must be published. It is queued when you save the post and regenerated on every update. Full runs include up to 1,000 posts with this option.
See Exclude a page from the cache for all per-post options.
WP-CLI #
wp powered-cache criticalcss --generate generates Critical CSS in the foreground and shows each URL. Add --clear to delete existing files first and clear the page cache afterwards, and --network-wide on multisite. See WP-CLI commands.
Connection requirements #
- Your site must be able to load its own pages over HTTP. Password protection, maintenance mode or a security plugin that blocks such requests stops generation.
- Your server must be able to send requests to the Powered Cache CSS service. If your host or firewall filters connections, see Service IP addresses.
- Generation runs with WordPress’s background scheduler. If WP-Cron is disabled, make sure a server cron job calls
wp-cron.php.
Troubleshooting #
Pages flash unstyled content #
The page has no generated Critical CSS, or the generated CSS misses an element. Check that the status is Healthy, add rules to Fallback Critical CSS or Append to Critical CSS, or use Generate specific Critical CSS for that page. See Broken layout after optimization.
The status says Needs attention #
A message such as HTML and CSS could not be extracted from … means your site could not load its own page. A message with an HTTP code comes from the CSS service. See CSS generation issues for each message and what to do.
For developers #
Filters: powered_cache_critical_css_source_urls (sample URLs per template), powered_cache_critical_css_post_type_query and powered_cache_critical_css_terms_query (sample sizes), powered_cache_critical_css_file_lookup, powered_cache_critical_css_output and powered_cache_critical_css_frontend_disable. See the hooks reference.