Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

css-bingo

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-bingo

Every byte counts when creating good user experiences for mobile devices and slow networks. Don't let the browser do unnecessary work. css-bingo finds all extraneous rules and selectors in your CSS, not used in your html, and removes them.

  • 1.4.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19
increased by72.73%
Maintainers
1
Weekly downloads
 
Created
Source

css-bingo

Every byte counts when creating good user experiences for mobile devices and slow networks. Don't let the browser do unnecessary work. css-bingo finds all extraneous rules and selectors in your CSS, not used in your html, and removes them.

Build Status NPM Version NSP Status Greenkeeper badge Coverage Status

Install

$ npm install css-bingo

Usage

const cssBingo = require('css-bingo');

const css = '.foo{color:#fff;}.bar{color:#000;}#baz{color:777}';
const html = '<br class="foo" />';

console.log(cssBingo(css, html));
// .foo{color:#fff;}

There are no options.

Selectors

Supported

Rules with supported selectors will be removed when the selector is not found in the provided html.

SelectorExample
**
.class.foo
.class.class.foo.bar
#id#baz
#id.class#baz.foo
elementp
element.classp.foo
element,elementdiv, p
element elementdiv p
element>elementdiv > p
element+elementdiv + p
element~elementp ~ ul

class names in both the class and the data-class attribute of html elements will be used.

<html>
    <body>
        <h1 class="foo" data-class="bar">Heading 1</h1>
    </body>
</html>

Unsupported

Element attributes, pseudo classes and pseudo elements of selectors are ignored when matching elements to selectors.

SelectorExample
[attribute][target]
[attribute=value][target=_blank]
[attribute~=value][title~=flower]
[attribute|=value][lang
[attribute^=value]a[href^="https"]
[attribute$=value]a[href$=".pdf"]
[attribute*=value]a[href*="w3schools"]
:activea:active
::afterp::after
::beforep::before
:checkedinput:checked
:disabledinput:disabled
:emptyp:empty
:enabledinput:enabled
:first-childp:first-child
::first-letterp::first-letter
::first-linep::first-line
:first-of-typep:first-of-type
:focusinput:focus
:hovera:hover
:in-rangeinput:in-range
:invalidinput:invalid
:lang(language)p:lang(it)
:last-childp:last-child
:last-of-typep:last-of-type
:linka:link
:not(selector):not(p)
:nth-child(n)p:nth-child(2)
:nth-last-child(n)p:nth-last-child(2)
:nth-last-of-type(n)p:nth-last-of-type(2)
:nth-of-type(n)p:nth-of-type(2)
:only-of-typep:only-of-type
:only-childp:only-child
:optionalinput:optional
:out-of-rangeinput:out-of-range
:read-onlyinput:read-only
:read-writeinput:read-write
:requiredinput:required
:root:root
::selection::selection
:target#news:target
:validinput:valid
:visiteda:visited
element-attributes

Element Attributes are ignored.

csshtmloutput
input[type=text]{color:#c00;}<input type="text"/>input[type=text]{color:#c00;}
input[type=text]{color:#c00;}<input type="password"/>input[type=text]{color:#c00;}
input[type=text]{color:#c00;}<button></button>
pseudo-classes

Pseudo Classes are ignored.

csshtmloutput
button:hover{color:#c00;}<button></button>button:hover{color:#c00;}
button:hover{color:#c00;}<input />
pseudo-elements

Pseudo Elements are ignored.

csshtmloutput
p::first-letter{color:#c00;}<p>foo bar</p>p::first-letter{color:#c00;}
p::first-letter{color:#c00;}<p></p>p::first-letter{color:#c00;}
p::first-letter{color:#c00;}<ul><li>foo></li><li>bar</li></ul>

Performance

1000 test runs on a 2.7 GHz Intel Core i5 MacBook Pro (early 2015) using unprocessed css and html from debitoor.

LibraryDuration
css-bingo65s
purify-css118s

Background

We are using css-bingo in nocms that we use to build our static websites @debitoor.

There are 5-10 people working on our websites at any given time during the work day and each of them submit pull-requests that are then built by our build agents. While pull requests can be built in parallel, merges to master can not. It is therefore important that we have a fast and stable build process.

I built css-bingo because none of the existing libraries that I could find had the accuracy and performance that we needed.

Contributing

Pull-requests are welcome. Check the issue list for something to do, or submit your own ideas. Performance improvements and bugfixes are always welcome.

Clone repository:

$ git clone git@github.com:jonatanpedersen/css-bingo.git

Install dependencies:

$ npm install

Test

mocha is used to describe and run tests.

Run tests:

$ npm test

Functional tests are described in ./test/tests.json.

Debugging

debug is used with the namespace css-bingo. Enable debugging by setting the DEBUG environment variable DEBUG=css-bingo.

Sat, 04 Feb 2017 22:24:42 GMT css-bingo removed rule: { type: 'rule', selectors: [], declarations: [ { type: 'declaration', property: 'color', value: 'red', position: Position { start: { line: 1, column: 22 }, end: { line: 1, column: 31 }, source: undefined } } ], position: Position { start: { line: 1, column: 17 }, end: { line: 1, column: 33 }, source: undefined } }

Coverage

istanbul and mocha are used to capture coverage data.

Run coverage:

$ npm run cover

Coverage data is written to ./coverage/ and a html report is written to ./coverage/lcov-report/index.html.

Continuous Integration

All pull requests and commits are built for the latest versions of node 4, 5, 6 and 7 by travis-ci, and coverage is reported to coveralls.io.

Licence

The MIT License (MIT)

Copyright (c) 2017 Jonatan Pedersen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

FAQs

Package last updated on 27 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc