2.4.27 • Published 3 months ago

@hint/hint-minified-js v2.4.27

Weekly downloads
218
License
Apache-2.0
Repository
github
Last release
3 months ago

Minify JavaScript (minified-js)

This hint checks whether JavaScript used by your web page is minified or not.

Why is this important?

Minifying your JavaScript is a great way to improve your page load time. This includes removing unused variables and methods, renaming variables and methods to smaller names, removing code comments, etc. Minification should generate a smaller file, and thus less code to parse.

What does the hint check?

This hint generates an "Improvement Index" value for the script content and compares it against a derived threshold value to determine whether the content is minified or not.

Improvement index is generated by comparing the number of tokens (from the abstract syntax tree generated from the code) with the total content length of a file.

const tokenRatio = tokenLength / contentLength;
const improvementIndex = Math.round((1 - tokenRatio) * 100);

if (improvementIndex > threshold) {
    // Script might be unminified
}

By default, the hint uses 75 as the threshold value to compare against. If the calculated improvement index value is greater than the threshold, the script will be flagged as unminified.

The value 75 was derived after running tests on some of the most used libraries and a couple of custom JavaScript files. See the sample repo with the test files and results.

Can the hint be configured?

By default, the hint uses 75 as the threshold value. But you can override that with a custom value in your .hintrc config:

{
    "connector": {...},
    "formatters": [...],
    "parsers": ["javascript"],
    "hints": {
        "minified-js": ["error", {
            "threshold": 80
        }]
    },
    ...
}

How to use this hint?

This package is installed automatically by webhint:

npm install hint --save-dev

To use it, activate it via the .hintrc configuration file:

{
    "connector": {...},
    "formatters": [...],
    "hints": {
        "minified-js": "error",
        ...
    },
    "parsers": ["javascript"],
    ...
}

Note: The recommended way of running webhint is as a devDependency of your project.

Further Reading

Here are some useful topics if you are new to minification:

NPM documentation: https://docs.npmjs.com/cli/install

2.4.27

3 months ago

2.4.26

1 year ago

2.4.25

1 year ago

2.4.24

2 years ago

2.4.23

2 years ago

2.4.22

2 years ago

2.4.19

2 years ago

2.4.21

2 years ago

2.4.20

2 years ago

2.4.18

2 years ago

2.4.17

3 years ago

2.4.16

3 years ago

2.4.15

3 years ago

2.4.14

3 years ago

2.4.13

3 years ago

2.4.12

3 years ago

2.4.11

3 years ago

2.4.10

3 years ago

2.4.9

4 years ago

2.4.8

4 years ago

2.4.7

4 years ago

2.4.6

4 years ago

2.4.5

4 years ago

2.4.4

4 years ago

2.4.3

5 years ago

2.4.2

5 years ago

2.4.1

5 years ago

2.4.0

5 years ago

2.3.11

5 years ago

2.3.10

5 years ago

2.3.9

5 years ago

2.3.8

5 years ago

2.3.7

5 years ago

2.3.6

5 years ago

2.3.5

5 years ago

2.3.4

5 years ago

2.3.3

5 years ago

2.3.2

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.2

5 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

1.0.0-beta.0

6 years ago