diff --git a/bin/cli.js b/bin/cli.js
index 7e7cfb9..a76b83d 100644
--- a/bin/cli.js
+++ b/bin/cli.js
@@ -111,6 +111,7 @@ if (cli.flags.reporter && cli.flags.reporter !== 'json' && cli.flags.reporter !=
xmlOutput = xmlOutput.replace(/(<[a-zA-Z]*>[^<]*)\n([^<]*<\/[a-zA-Z]*>)/g, '$1$2');
xmlOutput = xmlOutput.replace(/\0/g, '');
xmlOutput = xmlOutput.replace(/\uFFFF/g, '');
+ xmlOutput = xmlOutput.replace(/\u0002/g, '');
console.log(xmlOutput);
break;
diff --git a/front/src/views/rule.html b/front/src/views/rule.html
index f8d33d8..f011a2a 100644
--- a/front/src/views/rule.html
+++ b/front/src/views/rule.html
@@ -117,10 +117,6 @@
This metric counts the number of unused Unicode ranges inside each font. For example, one font could include Cyrillic glyphs but none of them are used on the page.
Because of technical limitations, Yellow Lab Tools checks each font against the glyphs of the entire page. As a result, estimated use is >= to reality. For example, if you read that 10 glyphs are \"possibly used\", it means that these 10 glyphs are used on the page but nothing guaranties that they are displayed using this font.
Tools such as Font Squirrel can remove some unicode ranges from a font.
In the case of an icon font, make sure you only keep the icons that are used on the website and to remove the others. Several tools are able to extract SVG images from a font, then some other tools can generate a font from the SVGs you want to keep.
", + "message": "This metric counts the number of unused Unicode ranges inside each font. For example, one font could include Cyrillic glyphs but none of them are used on the page.
It also reveals the number of ligatures (letters that are represented differently when close to each other) and hidden chars (glyphs not linked to the unicode system that can't be displayed on the web).
Because of technical limitations, Yellow Lab Tools checks each font against the glyphs of the entire page. As a result, estimated use is >= to reality. For example, if you read that 10 glyphs are \"possibly used\", it means that these 10 glyphs are used on the page but nothing guaranties that they are displayed using this font.
Tools such as Font Squirrel can remove some unicode ranges from a font.
In the case of an icon font, make sure you only keep the icons that are used on the website and to remove the others. Several tools are able to extract SVG images from a font, then some other tools can generate a font from the SVGs you want to keep.
", "isOkThreshold": 0, "isBadThreshold": 8, "isAbnormalThreshold": 12, diff --git a/lib/tools/redownload/fontAnalyzer.js b/lib/tools/redownload/fontAnalyzer.js index d83d0a8..0fab2f5 100644 --- a/lib/tools/redownload/fontAnalyzer.js +++ b/lib/tools/redownload/fontAnalyzer.js @@ -57,8 +57,17 @@ var FontAnalyzer = function() { var endTime = Date.now(); debug('Font analysis took %dms', endTime - startTime); - deferred.resolve(result); + // Mark fonts that are not used on the page (#224) + var fontIsUsed = false; + for (var range in result.unicodeRanges) { + if (result.unicodeRanges[range].numGlyphsInCommonWithPageContent > 0) { + fontIsUsed = true; + break; + } + } + result.isUsed = fontIsUsed; + deferred.resolve(result); } catch(error) { deferred.reject(error); } diff --git a/lib/tools/redownload/redownload.js b/lib/tools/redownload/redownload.js index c79c71c..824d6ed 100644 --- a/lib/tools/redownload/redownload.js +++ b/lib/tools/redownload/redownload.js @@ -103,6 +103,14 @@ var Redownload = function() { var metrics = {}; var offenders = {}; + // Remove unused fonts that a normal browser would not download (fix #224) + results = results.filter(function(result) { + if (result && result.fontMetrics) { + return result.fontMetrics.isUsed !== false; + } + return true; + }); + // Count requests offenders.totalRequests = listRequestsByType(results); metrics.totalRequests = offenders.totalRequests.total; @@ -500,6 +508,8 @@ var Redownload = function() { var ranges = []; var others = null; var rangeNames = Object.keys(req.fontMetrics.unicodeRanges); + var unicodePointsCount = 0; + var unusedRangesInFont = 0; rangeNames.forEach(function(rangeName) { var range = req.fontMetrics.unicodeRanges[rangeName]; @@ -508,18 +518,20 @@ var Redownload = function() { if (rangeName === 'Others') { if (range.numGlyphsInCommonWithPageContent === 0 && range.charset.length > 50) { range.underused = true; - unusedUnicodeRanges ++; + unusedRangesInFont ++; } + unicodePointsCount += range.charset.length; others = range; } else if (range.charset.length > 0) { // Now lets detect if the current Unicode range is unused. // Reminder: range.coverage = glyphs declared in this range, divided by the range size if (range.coverage > 0.25 && range.numGlyphsInCommonWithPageContent === 0) { range.underused = true; - unusedUnicodeRanges ++; + unusedRangesInFont ++; } + unicodePointsCount += range.charset.length; ranges.push(range); } }); @@ -539,7 +551,7 @@ var Redownload = function() { // And if less than 5% of the icons are used, let's report it as underused if (others && others.numGlyphsInCommonWithPageContent / others.charset.length <= 0.05) { - unusedUnicodeRanges ++; + unusedRangesInFont = 1; } // Not an icons font @@ -549,13 +561,21 @@ var Redownload = function() { ranges.push(others); } + var ligaturesOrHiddenChars = req.fontMetrics.numGlyphs - unicodePointsCount; + if (ligaturesOrHiddenChars > 25) { + unusedUnicodeRanges ++; + } + list.push({ url: req.url, weight: req.weightCheck.bodySize, isIconFont: false, - unicodeRanges: ranges + unicodeRanges: ranges, + ligaturesOrHiddenChars: ligaturesOrHiddenChars }); } + + unusedUnicodeRanges += unusedRangesInFont; } }); diff --git a/package.json b/package.json index 23b089b..52bb7ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yellowlabtools", - "version": "1.12.1", + "version": "1.12.3", "description": "Online tool to audit a webpage for performance and front-end quality issues", "license": "GPL-2.0", "author": { @@ -60,7 +60,7 @@ "meow": "3.7.0", "minimize": "2.0.0", "parse-color": "1.0.0", - "phantomas": "1.18.0", + "phantomas": "1.19.0", "ps-node": "0.1.4", "q": "1.4.1", "request": "2.79.0",