GithubHelp home page GithubHelp logo

cssvacuum's Introduction

CSSVacuum

optimize your critical rendering path

created at tech crunch disrupt sf 2013

CSSVacuum

Critical Rendering Path

Ilya Grigorik gave a great talk at Velocity on the Critical Rendering Path. Please check out his full presentation, but essentially, above the fold CSS should be inlined, and external CSS should by loaded asynchronously.

Eventually, this could work with the mod_pagespeed filter, so you don't have to determine the relevant styles manually.

CSSVacuum is...

a tool to help determine what css if 'critical'. It is a Chrome content script (extension) that will

  • determine all styles that are called above the fold
  • provide css to copy and paste into the new inlined header
  • provide a nice animation while it works

CSSVacuum isnt...

  • an out of the box solution to automatically inline css
  • ready for production

Example use in production...

  • setup a PhantomJS script, that utilizes portions of Chrome extension.
  • job that triggers Phantom to hit all relative pages on deploy (and clear existing cache keys)
  • cache the resulting CSS
  • if cache key exists, serve critical CSS inline, and full CSS async in footer

Install (official)

Install (source)

  • clone the repo
  • open Chrome and go to extensions
  • click developer mode, load unpacked extensions, and select repo
  • enable CSSVacuum

Use

  • with CSSVacuum installed, go to any url with ?CSSVacuum in query string. "http://amazon.com?CSSVacuum", for example.
  • click the CSSVacuum button
  • copy and paste the resulting css

Todo

  • Lots of room for improvement
  • Eliminate unecessary selectors (right now any selector, regardless of specificity, is included if it matches a class name)
  • Do guess work to limit resulting CSS filesize down to 14k.
  • PhantomJS script for production use.

cssvacuum's People

Contributors

ndreckshage 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cssvacuum's Issues

Exception on some sites - Failed to read the 'cssRules' property from 'CSSStyleSheet'

Hey there,

I've tried CSSVacuum (using the Chrome store version) on a bunch of different sites and often it works fine, except for the one site I actually want to use it for :( It's behind a login so I can't link you to it, but another example of a site it doesn't work on for me is this one: https://www.centrepointalliance.com.au/?CSSVacuum.

I see the following exception logged in the console:

Uncaught DOMException: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules
    at CSSStyleSheet.<anonymous> (chrome-extension://maellbbeahlpainnadomcgbcgmhjkbac/cssvacuum.js:127:13)
    at Function.each (chrome-extension://maellbbeahlpainnadomcgbcgmhjkbac/lib/jquery-2.0.3.min.js:2:4575)
    at CSSVacuum.browseOllivanders (chrome-extension://maellbbeahlpainnadomcgbcgmhjkbac/cssvacuum.js:126:7)
    at HTMLDocument.<anonymous> (chrome-extension://maellbbeahlpainnadomcgbcgmhjkbac/cssvacuum.js:52:13)
    at l (chrome-extension://maellbbeahlpainnadomcgbcgmhjkbac/lib/jquery-2.0.3.min.js:2:24882)
    at Object.fireWith [as resolveWith] (chrome-extension://maellbbeahlpainnadomcgbcgmhjkbac/lib/jquery-2.0.3.min.js:2:25702)
    at Function.ready (chrome-extension://maellbbeahlpainnadomcgbcgmhjkbac/lib/jquery-2.0.3.min.js:2:2900)
    at S (chrome-extension://maellbbeahlpainnadomcgbcgmhjkbac/lib/jquery-2.0.3.min.js:2:553)

Incorrectly outputs all of the styles.

All this seems to do right now is reorder styles, change some image paths, and strip out non-webkit prefixed properties, e.g. -moz-transform and -ms-transform. It's even including unused Font Awesome rules. FYI, I tested this in Chrome 52 and Opera 37.

Any ideas on what could be done to fix this?

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.