Skip to content

CSS optimization using critters for Nuxt

License

Notifications You must be signed in to change notification settings

nuxt-modules/critters

Folders and files

NameName
Last commit message
Last commit date
Feb 4, 2025
Mar 19, 2025
Nov 23, 2024
Apr 10, 2024
Jun 22, 2021
Aug 11, 2022
Dec 1, 2022
May 17, 2024
Jun 22, 2021
Nov 23, 2024
Nov 23, 2024
Mar 31, 2025
Mar 31, 2025
May 3, 2023
Nov 30, 2022
Dec 4, 2023
Dec 4, 2023

Repository files navigation

@nuxtjs/critters

npm version npm downloads Github Actions CI Codecov License

CSS optimization using beasties (formerly critters) for Nuxt

Features

  • Zero-configuration required
  • Enables CSS Extraction
  • Critical CSS automatically injected to page
  • Works with Nitro prerendering

Quick setup

  1. Add @nuxtjs/critters dependency to your project
yarn add @nuxtjs/critters # or npm install @nuxtjs/critters
  1. Add @nuxtjs/critters to the modules section of nuxt.config.js
{
  modules: [
    '@nuxtjs/critters',
  ],
}

How it works

Nuxt has a number of ways to optimize your CSS in production:

  1. ✅ Nuxt uses cssnano in the build step to minify CSS rules
  2. 📦 You can enable purgecss to remove unused CSS rules from your bundle.
  3. ✅ with @nuxtjs/critters you can now extract CSS files and load them separately, just inlining the CSS necessary to render the page.

Options

You can override the @nuxtjs/critters defaults like this:

// nuxt.config.js
import { defineNuxtConfig } from 'nuxt'
export default defineNuxtConfig({
  modules: ['@nuxtjs/critters'],
  critters: {
    // Options passed directly to beasties: https://github.com/danielroe/beasties#beasties-
    config: {
      // Default: 'media'
      preload: 'swap',
    },
  },
})

Development

  1. Clone this repository
  2. Enable corepack with corepack enable
  3. Install dependencies using pnpm install
  4. Start development server using pnpm dev

License

MIT License