Giter Club home page Giter Club logo

css-critic's Introduction

CSS critic

This is an experiment in determining critical CSS for a given URL. It uses PhantomJS to load the URL and execute some JavaScript that:

  • Extracts each of the CSS rules from all of the stylesheets on the page.
    • Stylesheets without screen or all media are skipped.
    • No other @media rules are filtered so that the critical CSS can apply to all screen sizes.
  • Gets all of the elements on the page whose bounding box is above the fold, or has display: none (in which case the bounding box cannot be determined).
  • Finds the intersection of the CSS rules by determining whether any of the "visible" elements matches any of their selectors via Element.matches.

If you want to try it out, clone this repo then:

npm install
node test.js [url]

This will produce a bunch of artifacts in the working directory:

  1. critical.css: the "critical" stylesheet.
  2. before.html and before.png: the HTML source and a screenshot of the URL before the CSS is modified.
  3. nocss.png: a screenshot of the URL after removing all of the CSS.
  4. after.html and after.png: the HTML source and a screenshot of the URL after the critical CSS has been inserted into the <head>.
  5. diff.png: the visual diff or before.png and after.png generated by Blink-diff.

See also

css-critic's People

Contributors

shawnbot avatar

Stargazers

 avatar  avatar

Watchers

 avatar

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.