Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/lete114/cache-hash
- Owner: Lete114
- License: mit
- Created: 2022-07-31T12:29:53.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-03T11:42:48.000Z (about 1 year ago)
- Last Synced: 2024-10-28T15:31:47.714Z (16 days ago)
- Language: TypeScript
- Size: 120 KB
- Stars: 17
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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: []
// }
```