Fingerprinting is a cache-busting technique which allows you to expire files when they actually change this is done by altering the filenames of the files. This way you can set far future expire headers without having to worry that your users might see stale or old files. Providing you with best of 2 worlds, cached assets for increased performance with sacrificing your ability to instantly modify files.
The module is released in the public npm registry and can be installed by running:
npm install --save fingerprinting
fingerprinting module is exposed as a single function that generates the
new filenames for your files. In all examples we assume that you've already
required the module as followed;
'use strict';var finger = ;
finger function accepts the following arguments:
- file The path to the file or filename of the file where we're generating
the file from. This is used to extract the file extension and read the file
contents if no
contentsoption is provided (please do note that reading is done using a sync fs method).
- options Optional configuration for the fingerprint generation:
- format: Template that specifies the format of the generated fingerprint.
- algorithm Hashing algorithm to be used to generate source hash. Defaults
- map Also generate an unique id for source maps. Defaults to
- env Environment that we're generating it for. It is used to generate the
suffix in the filename format. For example
minsuffix while a mising or development generates a
devsuffix. Defaults to
- content The actual content of the filename. This eliminates the need to
fs.readFileSyncwithin the code. It can be either a string or Buffer.
- format: Template that specifies the format of the generated fingerprint. Defaults to
The function returns an object with 2 keys:
- file This is the new filename for the given file.
- map If the map option was set to
truethis will contain the filename for your source map file.
var fs = ;fs;