{"id":427,"date":"2012-07-26T14:15:18","date_gmt":"2012-07-26T13:15:18","guid":{"rendered":"http:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/"},"modified":"2012-07-26T14:15:18","modified_gmt":"2012-07-26T13:15:18","slug":"how-to-find-unused-css-selectors-a-quick-solution","status":"publish","type":"post","link":"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/","title":{"rendered":"How to find unused CSS selectors, a quick solution"},"content":{"rendered":"<p>Was talking to a colleague today, and he mentioned the problem he was working on: <strong>trying to find site-wide unused CSS selectors<\/strong>. That is, having a static CSS file on disk, try to go through all the selectors in there and see if there&#39;s some matching elements in an entire site, crawling it page by page.<\/p>\n<p>I thought it was a really interesting problem, so I gave it a quick shot by glueing together <a href=\"https:\/\/metacpan.org\/module\/CSS::Tiny\" rel=\"nofollow\">CSS::Tiny<\/a>, <a href=\"https:\/\/metacpan.org\/module\/Mojo::UserAgent\" rel=\"nofollow\">Mojo::UserAgent<\/a> and <a href=\"https:\/\/metacpan.org\/module\/Mojo::DOM::CSS\" rel=\"nofollow\">Mojo::DOM::CSS<\/a>.<\/p>\n<p>This is what came out of it. I&#39;d say a decent first quick solution:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/3182239.js\"><\/script><\/p>\n<p>So I also learned about this <a href=\"https:\/\/github.com\/aanand\/deadweight\/\" rel=\"nofollow\">deadweight<\/a> project, that apparently also can crawl a site by logging in, kind of <code>WWW::Mechanize<\/code> style. Would be interesting to improve this initial solution :-)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Was talking to a colleague today, and he mentioned the problem he was working on: trying to find site-wide unused CSS selectors. That is, having a static CSS file on disk, try to go through all the selectors in there and see if there&#39;s some matching elements in an entire site, crawling it page by [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[49,52,51,50,48],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to find unused CSS selectors, a quick solution - Random hacking<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to find unused CSS selectors, a quick solution - Random hacking\" \/>\n<meta property=\"og:description\" content=\"Was talking to a colleague today, and he mentioned the problem he was working on: trying to find site-wide unused CSS selectors. That is, having a static CSS file on disk, try to go through all the selectors in there and see if there&#039;s some matching elements in an entire site, crawling it page by [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/\" \/>\n<meta property=\"og:site_name\" content=\"Random hacking\" \/>\n<meta property=\"article:published_time\" content=\"2012-07-26T13:15:18+00:00\" \/>\n<meta name=\"author\" content=\"cosimo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"cosimo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/\"},\"author\":{\"name\":\"cosimo\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"headline\":\"How to find unused CSS selectors, a quick solution\",\"datePublished\":\"2012-07-26T13:15:18+00:00\",\"dateModified\":\"2012-07-26T13:15:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/\"},\"wordCount\":137,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"keywords\":[\"cpan\",\"css\",\"mojolicious\",\"perl\",\"web\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/\",\"name\":\"How to find unused CSS selectors, a quick solution - Random hacking\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\"},\"datePublished\":\"2012-07-26T13:15:18+00:00\",\"dateModified\":\"2012-07-26T13:15:18+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to find unused CSS selectors, a quick solution\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\",\"name\":\"Random hacking\",\"description\":\"Assume nothing. Code defensively. Keep it simple, stupid!\",\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.streppone.it\/cosimo\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\",\"name\":\"cosimo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g\",\"caption\":\"cosimo\"},\"logo\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/author\/cosimo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to find unused CSS selectors, a quick solution - Random hacking","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/","og_locale":"en_US","og_type":"article","og_title":"How to find unused CSS selectors, a quick solution - Random hacking","og_description":"Was talking to a colleague today, and he mentioned the problem he was working on: trying to find site-wide unused CSS selectors. That is, having a static CSS file on disk, try to go through all the selectors in there and see if there&#39;s some matching elements in an entire site, crawling it page by [&hellip;]","og_url":"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/","og_site_name":"Random hacking","article_published_time":"2012-07-26T13:15:18+00:00","author":"cosimo","twitter_card":"summary_large_image","twitter_misc":{"Written by":"cosimo","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/#article","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/"},"author":{"name":"cosimo","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"headline":"How to find unused CSS selectors, a quick solution","datePublished":"2012-07-26T13:15:18+00:00","dateModified":"2012-07-26T13:15:18+00:00","mainEntityOfPage":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/"},"wordCount":137,"commentCount":0,"publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"keywords":["cpan","css","mojolicious","perl","web"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/","url":"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/","name":"How to find unused CSS selectors, a quick solution - Random hacking","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website"},"datePublished":"2012-07-26T13:15:18+00:00","dateModified":"2012-07-26T13:15:18+00:00","breadcrumb":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2012\/07\/how-to-find-unused-css-selectors-a-quick-solution\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.streppone.it\/cosimo\/blog\/"},{"@type":"ListItem","position":2,"name":"How to find unused CSS selectors, a quick solution"}]},{"@type":"WebSite","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website","url":"https:\/\/www.streppone.it\/cosimo\/blog\/","name":"Random hacking","description":"Assume nothing. Code defensively. Keep it simple, stupid!","publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.streppone.it\/cosimo\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1","name":"cosimo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g","caption":"cosimo"},"logo":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/"},"url":"https:\/\/www.streppone.it\/cosimo\/blog\/author\/cosimo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/427"}],"collection":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/comments?post=427"}],"version-history":[{"count":0,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/427\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/media?parent=427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/categories?post=427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/tags?post=427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}