0.5.3 • Published 1 year ago

hasset v0.5.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Append unique hashes to assets referenced in your views to aggressively cache them while guaranteeing that clients receive the most recent versions.

Installation

npm i hasset

Usage

Running the following command will scan asset files found in the roots path(s) and replace their references with hashed versions in the refs path(s):

npx hasset --roots="path/to/scan/assets1/,path/to/scan/assets2/" --refs="views/path/to/append/hashes1/,views/path/to/append/hashes2/"

Example (Fastify)

Register @fastify/static:

await fastify.register(import("@fastify/static"), {
  root: new URL("assets/", import.meta.url).pathname,
  prefix: "/p/assets/",
  wildcard: false,
  index: false,
  immutable: true,
  maxAge: process.env.NODE_ENV === "production" ? 31536000 * 1000 : 0,
});

Add the hasset command to the build script:

"scripts": {
  "build": "npx hasset --roots=assets/ --refs=views/,routes/",
},

Make sure to npm run build in Dockerfile:

FROM node:latest

WORKDIR /app

COPY package*.json ./

RUN npm ci --include=dev

COPY . .

RUN npm run build

RUN npm prune --production

CMD ["npm", "start"]

Demo

A full project that uses hasset can be found in the example folder:

cd example

npm i

npm run build

node .
0.5.3

1 year ago

0.5.2

1 year ago

0.5.0

1 year ago

0.5.1

1 year ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago