analyze-css
CSS selectors complexity and performance analyzer. analyze-css is built as a set of rules bound to events fired by CSS parser. Each rule can generate metrics and add "offenders" with more detailed information (see Usage section for an example).
- Analyze CSS Demo
Install
analyze-css comes as a "binary" for command-line and as CommonJS module. Run the following to install them globally:
npm install --global analyze-css
Usage
Command line tool
You can use analyze-css "binary" to analyze local CSS files or remote CSS assets:
analyze-css --file examples/elecena.cssanalyze-css --url http://jigsaw.w3.org/css-validator/style/base.css
You can provide CSS via stdin as well (notice the dash: -):
echo ".foo {margin: 0 \!important}" | analyze-css -
This will emit JSON formatted results on stdout. Use --pretty (or -p shortcut) option to make the output readable for human beings.
Basic HTTP authentication can be provided through the options --auth-user and --auth-pass.
CommonJS module
var analyzer = require('analyze-css');new analyzer('.foo {margin: 0 !important}', function(err, results) { console.error(err); console.log(results); // example? see below});
// options can be providedvar opts = { 'noOffenders': true};new analyzer('.foo {margin: 0 !important}', opts, function(err, results) { console.error(err); console.log(results); // example? see below});```
grunt task
Created by @DeuxHuitHuit
npm i grunt-contrib-analyze-css
It uses configurable threshold and compares the analyze-css result with it.
Results
{ "generator": "analyze-css v0.8.0", "metrics": { "base64Length": 11332, "redundantBodySelectors": 0, "redundantChildNodesSelectors": 1, "colors": 106, "comments": 1, "commentsLength": 68, "complexSelectors": 37, "complexSelectorsByAttribute": 3, "duplicatedSelectors": 7, "duplicatedProperties": 24, "emptyRules": 0, "expressions": 0, "oldIEFixes": 51, "imports": 0, "importants": 3, "mediaQueries": 0, "multiClassesSelectors": 74, "parsingErrors": 0, "oldPropertyPrefixes": 79, "propertyResets": 0, "qualifiedSelectors": 28, "specificityIdAvg": 0.04, "specificityIdTotal": 25, "specificityClassAvg": 1.27, "specificityClassTotal": 904, "specificityTagAvg": 0.79, "specificityTagTotal": 562, "selectors": 712, "selectorLengthAvg": 1.5722460658082975, "selectorsByAttribute": 92, "selectorsByClass": 600, "selectorsById": 25, "selectorsByPseudo": 167, "selectorsByTag": 533, "universalSelectors": 5, "length": 55173, "rules": 433, "declarations": 1288 }, "offenders": { "importants": [ ".foo {margin: 0 !important}" ] }}
Metrics
- base64Length: total length of base64-encoded data in CSS source (will warn about base64-encoded data bigger than 4 kB)
- redundantBodySelectors: number of redundant body selectors (e.g. body .foo, section body h2, but not body > h1)
- redundantChildNodesSelectors: number of redundant child nodes selectors (e.g. ul li, table tr)
- colors: number of unique colors used in CSS
- comments: number of comments in CSS source
- commentsLength: length of comments content in CSS source
- complexSelectors: number of complex selectors (consisting of more than three expressions, e.g. header ul li .foo)
- complexSelectorsByAttribute: number of selectors with complex matching by attribute (e.g. [class$="foo"])
- duplicatedSelectors: number of CSS selectors defined more than once in CSS source
- duplicatedProperties: number of CSS property definitions duplicated within a selector
- emptyRules: number of rules with no properties (e.g. .foo { })
- expressions: number of rules with CSS expressions (e.g. expression( document.body.clientWidth > 600 ? "600px" : "auto" ))
- oldIEFixes: number of fixes for old versions of Internet Explorer (e.g. * html .foo {} and .foo { *zoom: 1 }, read more)
- imports number of @import rules
- importants: number of properties with value forced by !important
- mediaQueries: number of media queries (e.g. @media screen and (min-width: 1370px))
- multiClassesSelectors: reports selectors with multiple classes (e.g. span.foo.bar)
- parsingErrors: number of CSS parsing errors
- oldPropertyPrefixes: number of properties with no longer needed vendor prefix, powered by data provided by autoprefixer (e.g. --moz-border-radius)
- propertyResets: number of accidental property resets
- qualifiedSelectors: number of qualified selectors (e.g. header#nav, .foo#bar, h1.title)
- specificityIdAvg: average specificity for ID
- specificityIdTotal: total specificity for ID
- specificityClassAvg: average specificity for class, pseudo-class or attribute
- specificityClassTotal: total specificity for class, pseudo-class or attribute
- specificityTagAvg: average specificity for element
- specificityTagTotal: total specificity for element
- selectors: number of selectors (e.g. .foo, .bar { color: red } is counted as two selectors - .foo and .bar)
- selectorLengthAvg: average length of selector (e.g. for .foo .bar, #test div > span { color: red } will be set as 2.5)
- selectorsByAttribute: number of selectors by attribute (e.g. .foo[value=bar])
- selectorsByClass: number of selectors by class
- selectorsById: number of selectors by ID
- selectorsByPseudo: number of pseudo-selectors (e,g. :hover)
- selectorsByTag: number of selectors by tag name
- universalSelectors: number of selectors trying to match every element (e.g. .foo > *)
- length: length of CSS source (in bytes)
- rules: number of rules (e.g. .foo, .bar { color: red } is counted as one rule)
- declarations: number of declarations (e.g. .foo, .bar { color: red } is counted as one declaration - color: red)
Read more
- Writing Efficient CSS (by Mozilla)
- Optimize browser rendering (by Google)
- Profiling CSS for fun and profit. Optimization notes.
- CSS specificity
- CSS Selector Performance has changed! (For the better) (by Nicole Sullivan)
- CSS Performance (by Paul Irish)
- GitHub's CSS Performance (by Joh Rohan)
Dev hints
Running tests and linting the code:
npm test && npm run-script lint
Turning on debug mode (i.e. verbose logging to stderr via debug module):
DEBUG=analyze-css* analyze-css ...
项目地址: https://github.com/macbre/analyze-css

HTML的作用是通过标签和属性定义网页的结构和内容。1.HTML通过到、等标签组织内容,使其易于阅读和理解。2.使用语义化标签如、等增强可访问性和SEO。3.优化HTML代码可以提高网页加载速度和用户体验。

htmlisaspecifictypefodyfocusedonstructuringwebcontent,而“代码” badlyLyCludEslanguagesLikeLikejavascriptandPytyPythonForFunctionality.1)htmldefineswebpagertuctureduseTags.2)“代码”代码“ code” code code code codeSpassSesseseseseseseseAwiderRangeLangeLangeforLageforLogageforLogicIctInterract

HTML、CSS和JavaScript是Web开发的三大支柱。1.HTML定义网页结构,使用标签如、等。2.CSS控制网页样式,使用选择器和属性如color、font-size等。3.JavaScript实现动态效果和交互,通过事件监听和DOM操作。

HTML定义网页结构,CSS负责样式和布局,JavaScript赋予动态交互。三者在网页开发中各司其职,共同构建丰富多彩的网站。

HTML适合初学者学习,因为它简单易学且能快速看到成果。1)HTML的学习曲线平缓,易于上手。2)只需掌握基本标签即可开始创建网页。3)灵活性高,可与CSS和JavaScript结合使用。4)丰富的学习资源和现代工具支持学习过程。

AnexampleOfAstartingTaginHtmlis,beginSaparagraph.startingTagSareEssentialInhtmlastheyInitiateEllements,defiteTheeTheErtypes,andarecrucialforsstructuringwebpages wepages webpages andConstructingthedom。

如何设计菜单中的虚线分割效果?在设计菜单时,菜名和价格的左右对齐通常不难实现,但中间的虚线或点如何...

网页代码编辑器中的HTML元素分析许多在线代码编辑器允许用户输入HTML、CSS和JavaScript代码。最近,有人提出了一...


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

记事本++7.3.1
好用且免费的代码编辑器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。