Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lete114/cache-hash

Create hash for static resources to break http cache
https://github.com/lete114/cache-hash

Last synced: 14 days ago
JSON representation

Create hash for static resources to break http cache

Awesome Lists containing this project

README

        

# Cache-hash

![visitor](https://visitor_badge.deta.dev/?pageID=github.Lete114.cache-hash)
![version](https://img.shields.io/npm/v/cache-hash?color=critical&logo=npm)
![license](https://img.shields.io/npm/l/cache-hash?color=ee5535)

## Installation

```bash
npm install cache-hash -D
```

Or global install

```bash
npm install cache-hash -g
```

## Use CLI

```bash
cache-hash --target source --output public
```

Or

```bash
cache-hash -t source -o public
```

See help `cache-hash --help` for more configuration

```bash
$ cache-hash --help
Usage: cache-hash [options]

Options:
-v, --version output the version number
-t, --target Target resource directory (default: "./")
-o, --output Output directory, If not set, he will overwrite the "target" content
--size Generate hash length (default: 10)
--key Version key (default: "v")
--lazy Select the specified dom element. Example: `'[["a","b"]]'` selects the img tag, and the img tag must contain the lazy attribute (default: [['script', 'src'], ['link', 'href'], ['img', 'src']])
--html Generate hash for html referenced resources (default: true)
--css Generate hash for css referenced resources (default: true)
--js Generate hash for js referenced resources (default: true)
--style Generating hashes for resources referenced by style tags (<style>) (default: true)
--script <script> Generating hashes for resources referenced by script tags (<script>) (default: true)
--ignore <ignore...> Ignore the specified directory or file (default: [])
-h, --help display help for command
```

## Use JavaScript API

```js
const cacheHash = require('cache-hash')

cacheHash({
target: 'source',
output: 'public'
})

// Please see the cli help parameter description above
// defualtOptions: {
// target: process.cwd(), // Current command line path
// output: process.cwd(), // Current command line path
// size: 10,
// versionKey: 'v',
// selectAll: [ [ 'script', 'src' ], [ 'link', 'href' ], [ 'img', 'src' ] ],
// html: true,
// css: true,
// js: true,
// style: true,
// script: true,
// ignore: []
// }
```