critical path css,GitHub - bezoerb/grunt-critical: Grunt task to extract & inline critical-path CSS ...

grunt-critical

Grunt plugin to extract & inline critical-path CSS from HTML

68747470733a2f2f62616467652e667572792e696f2f6a732f6772756e742d637269746963616c2e737667

badge.svg

68747470733a2f2f64617669642d646d2e6f72672f62657a6f6572622f6772756e742d637269746963616c2e737667

Getting Started

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

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-critical');

Critical task

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.

Usage

Use the grunt-critical task by specifying a target destination (file) for your critical CSS. Below this is test/generated/critical.css.

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 test/fixture/index.html.

critical: {

test: {

options: {

base: './',

css: [

'test/fixture/styles/main.css',

'test/fixture/styles/bootstrap.css'

],

width: 320,

height: 70

},

src: 'test/fixture/index.html',

dest: 'test/generated/critical.css'

}

}

If the dest file is a stylesheet, the resulting critical-path css is saved to this file for later use.

If dest points to an Markup file (HTML, PHP, etc.) the resulting CSS gets inlined and the exiting stylesheets are

wrapped in a javascript function to load them asynchronously as well as a noscript block for users with JavaScript disabled

critical: {

test: {

options: {

base: './',

css: [

'test/fixture/styles/main.css',

'test/fixture/styles/bootstrap.css'

],

width: 320,

height: 70

},

src: 'test/fixture/index.html',

dest: 'test/generated/index-critical.html'

}

}

Options

For a full list of options see critical

License

(C) Ben Zörb 2014, released under an MIT license

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值