瀏覽代碼

Compare minified files on gzipped size

Gaël Métais 10 年之前
父節點
當前提交
31d80791a9
共有 3 個文件被更改,包括 20 次插入42 次删除
  1. 5 8
      front/src/views/rule.html
  2. 13 32
      lib/metadata/policies.js
  3. 2 2
      lib/metadata/scoreProfileGeneric.json

+ 5 - 8
front/src/views/rule.html

@@ -146,11 +146,6 @@
                         <url-link url="offender" max-length="100"></url-link>
                     </div>
 
-                    <div ng-if="policyName === 'assetsNotGzipped'">
-                        <url-link url="offender.file" max-length="100"></url-link>
-                        ({{offender.type}})
-                    </div>
-
                     <div ng-if="policyName === 'cachingTooShort'">
                         <url-link url="offender.file" max-length="100"></url-link>
                         cached for <b>{{offender.ttlWithUnit}} {{offender.unit}}</b>
@@ -241,10 +236,12 @@
             </div>
             <div ng-repeat="file in rule.offendersObj.list.files | orderBy:'-gain'">
                 <div>
-                    <url-link url="file.url" max-length="60"></url-link>
+                    <url-link url="file.url" max-length="70"></url-link>
                 </div>
-                <div>{{file.original | bytes}}</div>
-                <div>{{file.minified | bytes}}</div>
+                <div ng-if="!file.afterCompression">{{file.original | bytes}} (gzipped)</div>
+                <div ng-if="file.afterCompression">{{file.original | bytes}} ({{file.afterCompression | bytes}} gzipped)</div>
+                <div ng-if="!file.afterCompression">{{file.afterOptimizationAndCompression | bytes}} (gzipped)</div>
+                <div ng-if="file.afterCompression">{{file.optimized | bytes}} ({{file.afterOptimizationAndCompression | bytes}} gzipped)</div>
                 <div><b>-{{file.gain | bytes}}</b></div>
             </div>
         </div>

+ 13 - 32
lib/metadata/policies.js

@@ -872,16 +872,26 @@ var policies = {
         "hasOffenders": true,
         "unit": 'bytes'
     },
-    "fileMinification": {
+    "gzipCompression": {
         "tool": "weightChecker",
-        "label": "File minification",
-        "message": "<p>This is the weight that could be saved if all text resources were correctly minified.</p><p>The tools in use here are <b>UglifyJS</b>, <b>clean-css</b> and <b>HTMLMinifier</b>. These tools are so good that some of your minified files can be marked as unminified. Change your tool it this happens :)</p><p>The gains of minification are generally small, but the impact can be high when these text files are loaded on the critical path.</p>",
+        "label": "Gzip compression",
+        "message": "<p>Mesures the number of bytes that could be saved by compressing file transfers.</p><p>Gzip is a powerfull weight reducer and should be enabled on text-based assets in your server's configuration. Note that gzipping small files (< 1 KB) is arguable, and that some assets such as images should not be gzipped as they are already compressed. <a href=\"https://gist.github.com/gmetais/971ce13a1fbeebd88445\" target=\"_blank\">Here</a> is a list of Content-Types that should be gzipped.</p>",
         "isOkThreshold": 20480,
         "isBadThreshold": 81920,
         "isAbnormalThreshold": 153600,
         "hasOffenders": true,
         "unit": 'bytes'
     },
+    "fileMinification": {
+        "tool": "weightChecker",
+        "label": "File minification",
+        "message": "<p>This is the weight that could be saved if all text resources were correctly minified.</p><p>The tools in use here are <b>UglifyJS</b>, <b>clean-css</b> and <b>HTMLMinifier</b>. These tools are so good that some of your minified files can be marked as unminified. Change your tool it this happens :)</p><p>The gains of minification are generally small, but the impact can be high when these text files are loaded on the critical path.</p>",
+        "isOkThreshold": 10240,
+        "isBadThreshold": 76800,
+        "isAbnormalThreshold": 122880,
+        "hasOffenders": true,
+        "unit": 'bytes'
+    },
     "requests": {
         "tool": "phantomas",
         "label": "Total requests number",
@@ -1099,35 +1109,6 @@ var policies = {
         "isAbnormalThreshold": 1,
         "hasOffenders": true
     },
-    "assetsNotGzipped": {
-        "tool": "phantomas",
-        "label": "Not gzipped",
-        "message": "<p>This is the number of requests that should be compressed with gzip but aren't.</p><p>Gzip is a powerfull weight reducer and should be enabled on text-based assets in your server's configuration. Note that gzipping small files (< 1 KB) is arguable, and that some assets such as images should not be gzipped as they are already compressed. <a href=\"https://gist.github.com/gmetais/971ce13a1fbeebd88445\" target=\"_blank\">Here</a> is a list of Content-Types that should be gzipped.</p>",
-        "isOkThreshold": 0,
-        "isBadThreshold": 12,
-        "isAbnormalThreshold": 20,
-        "hasOffenders": true,
-        "offendersTransformFn": function(offenders) {
-            return {
-                count: offenders.length,
-                list: offenders.map(function(offender) {
-                    var parts = /^([^ ]*) \((.+)\)$/.exec(offender);
-
-                    if (!parts) {
-                        debug('assetsNotGzipped offenders transform function error with "%s"', offender);
-                        return {
-                            parseError: offender
-                        };
-                    }
-
-                    return {
-                        file: parts[1],
-                        type: parts[2]
-                    };
-                })
-            };
-        }
-    },
     "closedConnections": {
         "tool": "phantomas",
         "label": "Connections closed",

+ 2 - 2
lib/metadata/scoreProfileGeneric.json

@@ -74,8 +74,8 @@
             "policies": {
                 "totalWeight": 5,
                 "imageOptimization": 2,
-                "fileMinification": 1,
-                "assetsNotGzipped": 2
+                "gzipCompression": 2,
+                "fileMinification": 1
             }
         },
         "requests": {