Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Critical CSS

Security covered Maintenance fixes only 2,477 sites

This module embeds critical CSS directly into the HTML head of your pages, then loads all other CSS asynchronously. This improves initial page load performance by ensuring the most important styles are applied immediately.

Embeds a critical CSS file into a page's HTML head, and loads the rest of non-critical CSS asynchronously.

INTRODUCTION

  1. This module looks for a CSS file inside your active theme directory. This CSS filename should match any of:
    • bundle type (i.e., "article.css")
    • entity id (i.e., "123.css")
    • url (i.e., "my-article.css")
  2. If none of the previous filenames can be found, this module will search for a file named "default-critical.css".
  3. A hook is provided ("critical_css_file_paths_suggestion") in case another filename is needed.
  4. If any of the above paths is found, this module loads the CSS file contents inside a <style> tag placed in the HTML head.
  5. Any other CSS file used in the HTML head is loaded asynchronously using this
    strategy. No need for polyfills.

REQUIREMENTS

Before this module can do anything, you should generate the critical CSS of the page.

This can be achieved by running a Gulp task to automatically extract the critical CSS of any page. Using Addy Osmani's critical package is highly recommended.

Another option is Filament Group's criticalCSS.

There are also some critical CSS online generators to get that CSS without effort.

The extracted critical CSS must be saved in a directory inside the current theme, at the location specified on Critical CSS's config page.

CONFIGURATION

Module must be enabled in /admin/config/development/performance/critical-css. This allows for easy enabling/disabling without uninstalling it.

DEBUGGING

When twig debug is enabled, Critical CSS will show all the possible file paths that is trying to find inside a css comment.

If you see ‘NONE MATCHED’, check to see if you are logged in and make sure Critical CSS is enabled for logged-in users. Since the contents of the critical CSS files are generated emulating an anonymous visit, I recommend disabling this feature once you’ve finished testing.

Drupal 10–11

Ask your assistant about Critical CSS

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
10
Tracked since
Dec 2023
Latest release
2 months ago
Releases (12 mo)
4 ▲ from 0
Maintenance
Active

Release Timeline

Releases

Version Type Core PHP Release date
2.0.7 Stable 10–11 Aug 26, 2026
2.0.6 Stable 10–11 Aug 21, 2026
2.0.5 Stable 9–11 Aug 21, 2026
2.0.4 Stable 9–11 Aug 21, 2026
2.0.3 Stable 9–11 Nov 5, 2024
2.0.2 Stable 9–11 Oct 29, 2024
2.0.1 Stable 9–11 Oct 29, 2024
2.0.0 Stable 9–10 Jan 18, 2024
2.0.x-dev Dev 10–11 Jan 18, 2024
8.x-1.20 Stable 9–11 Dec 29, 2023