Grunt task to extract & inline critical-path CSS from HTML
Grunt plugin to extract & inline critical-path CSS from HTML
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-critical --save-dev
Run this task with the
grunt critical command.
Task targets, files and options may be specified according to the grunt Configuring tasks guide.
Generate critical path css and inline it with critical.
grunt-critical task by specifying a target destination (file) for your critical CSS. Below this is
Along-side, specify the input HTML file you would like scanned as well as the width and height of the critical viewport.
In this case
critical:test:options:base: './'css:'test/fixture/styles/main.css''test/fixture/styles/bootstrap.css'width: 320height: 70src: 'test/fixture/index.html'dest: 'test/generated/critical.css'
dest file is a stylesheet, the resulting critical-path css is saved to this file for later use.
dest points to an Markup file (HTML, PHP, etc.) the resulting CSS gets inlined and the exiting stylesheets are
critical:test:options:base: './'css:'test/fixture/styles/main.css''test/fixture/styles/bootstrap.css'width: 320height: 70src: 'test/fixture/index.html'dest: 'test/generated/index-critical.html'
For a full list of options see critical
(C) Ben Zörb 2014, released under an MIT license