Git Product home page Git Product logo

cave's Introduction

cave

Remove critical CSS from your stylesheet after inlining it in your pages

If you don't understand the purpose of this module, refer to penthouse which extracts critical CSS from a file, but doesn't remove it. Using this tool you can take the styles produced by an extraction tool like penthouse and actually remove them from your stylesheet.

Install

npm install cave --save

API

The cave exposes a single function that takes the file path to a stylesheet and a string containing valid CSS you want to remove from the provided stylesheet.

cave(stylesheet, options)

The options object contains the following properties.

Property Description
css The CSS rules to remove from the stylesheet. e.g: a { color: #f00; }

Cave will produce an AST and remove any matching rules, then the resulting CSS diff will be returned.

CLI

Cave works well with standard input.

cat path/to/file | cave <stylesheet> > slim.css

You can also pass in the critical CSS file as an option.

cave --css path/to/file <stylesheet> > slim.css

Tests

Run tests using npm.

npm test

License

MIT

cave's People

Contributors

bevacqua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cave's Issues

src/cave.js doesn't work properly

Hi,

I tried your script but it doesn't work properly.
Doesn't work:

var cave = require('cave');
var fs = require('fs');
cave('deploy/css/style.css', fs.readFileSync('deploy/css/critical.css', { encoding: 'utf8' }), function() {
     console.log('OUTPUT');
 })

Error: Warning: Maximum call stack size exceeded Use --force to continue.

It seems to the css library has some problems to parse the css-file.

Works:
cat deploy/css/style.css | ./node_modules/cave/bin/cave deploy/css/critical.css > deploy/css/slim.css

How can i fix it? Can you help me?

Kind regards
Stephan

How would this be used in a gulp workflow?

I'm keen to use this programatically and pair it with critical in a gulp workflow, but i have no idea where to start. Any chance you can add a snippet to the documentation?

I've also noticed that when passing 2 minified css files into cave, the output is an un-minified file - which is a little fiddly as it requires further processing.

cat .temp/production/assets/css/site.css | npm run cave .temp/production/assets/css/critical.css > main.css

(main.css is un-minified.)

Done callback

Was the done callback removed? just curious

var diff = cave(pathToFile('style.css'), {
            css: criticalCss
});
console.log(diff) // outputs the css

but adding a function after the css object never gets called

var diff = cave(pathToFile('style.css'), {
            css: criticalCss
}, function(){
   console.log('done'); // never gets called
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.