Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache-digest CLI #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 36 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,57 @@
cache-digest.js
======
# cache-digest.js

[![Build Status](https://travis-ci.org/h2o/cache-digest.js.svg?branch=master)](https://travis-ci.org/h2o/cache-digest.js)

[Service Worker](https://developer.mozilla.org/docs/Web/API/Service_Worker_API) implementation of [Cache Digests for HTTP/2 (draft 01)](https://tools.ietf.org/html/draft-kazuho-h2-cache-digest-01)

Warning
------
## Warning


* WIP; the code is in early-beta stage
* only supports sending of _fresh_ digests without etag

How to Use
------
## How to Use

1. install cache-digest.js into the root directory of the website
2. add `<script src="/cache-digest.js"></script>` to your web pages
3. adjust the web server configuration to send:
* `service-worker-allowed: /` response header
* `link: <push-URL>; rel="preload"` response header (see [spec](https://w3c.github.io/preload/))

Calculating Digests at Command Line
------
## Command Line Interface

```bash
Usage: cache-digest [-b] [-p=pbits] URL1 URL2...
```

Install using NPM to provide a command line interface.

You can run cli.js to calculate cache digests manually.
```bash
# locally for npm scripts
npm install cache-digest-cli

# or globally for system-wide use
npm install --global cache-digest-cli
```
% node cli.js -b https://example.com/style.css https://example.com/jquery.js https://example.com/shortcut.css
EeUM-QA

Example:
```bash
cache-digest -b https://example.com/style.css https://example.com/jquery.js https://example.com/shortcut.css
# Output: EeUM-QA
```

In the above example, `-b` option is used so that the digest would be encoded using [base64url](https://tools.ietf.org/html/rfc4648#section-5). Please refer to `-h` (help) option for more information.
### Options

#### `-b`

Encode the digest as per the [base64url](https://tools.ietf.org/html/rfc4648#section-5) specification.

If this option is not specified the output is streamed as raw binary data to `STDOUT`.

#### `-p=pbits`

Where **pbits** is an integer representing the probability of collisions. Maximum 31 bits per hash.

#### `-h` or `--help`

Display help information.
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function main(argv) {
if (opt == "-")
break;
if (opt == "-h" || opt == "--help") {
console.log("Usage: node cmd.js [-b] [-p=pbits] URL1 URL2...")
console.log("Usage: cache-digest [-b] [-p=pbits] URL1 URL2...")
return 0;
} else if (opt == "-b") {
useBase64 = 1;
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "cache-digest",
"name": "cache-digest-cli",
"version": "1.0.0",
"description": "Service Worker implementation of Cache Digests for HTTP/2 (draft 01) https://tools.ietf.org/html/draft-kazuho-h2-cache-digest-01",
"main": "cache-digest.js",
"bin": "cli.js",
"bin": {
"cache-digest": "cli.js"
},
"scripts": {
"test": "node test.js"
},
Expand Down