Created
December 6, 2013 11:14
-
-
Save hallvors/7822130 to your computer and use it in GitHub Desktop.
A method that tries to remove CSS rules that do not apply to anything in the current page, aids in minimising test cases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function minimizeCSS(){ | |
| var s = document.styleSheets[0].cssRules; | |
| var j=s.length-1, ar=[]; | |
| try{ | |
| for(;j>=0;j--){ | |
| if(document.querySelectorAll(s[j].selectorText).length>0)ar.push(s[j].cssText); | |
| } | |
| }catch(e){ | |
| console.log('error for style #'+j) | |
| } | |
| document.body.appendChild(document.createElement('pre')).appendChild(document.createTextNode(ar.join('\n'))); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment