filamentgroup / criticalCSS

Finds the Above the Fold CSS for your page, and outputs it into a file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Give the page a second or so to enhance before running criticalCSS

scottjehl opened this issue · comments

I noticed that criticalCSS often runs before JS fully applies to a page, and that can mean certain selectors won't apply, among other things. Adding a short delay after page load seems to work around this issue, at least for the filamentgroup.com site.

I currently have this in the task runner and it's working:

function runit(){
                var crit = cc.criticalCSS( filename, opts );
                if( crit.length === 0 ){
                    throw new Error( "criticalCSS didn't run or no critical css, that seems unlikely" );
                } else {
                    system.stdout.write(crit);
                    phantom.exit();
                }
}

// give the JS a second to run
setTimeout( runit, 1000 );

cc @jefflembeck

Never mind. This doesn't seem to fix it. Still looking...

I think I'm seeing a different issue entirely - closing for now