# @ndcode/min_js_cache

> JS minimizer, caching front-end with live recompilation

Latest version **0.1.0** (published 2018-11-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @ndcode/min_js_cache
pnpm add @ndcode/min_js_cache
yarn add @ndcode/min_js_cache
bun add @ndcode/min_js_cache
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2018-11-27 |
| First published | 2018-11-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.4.0 |
| Dependencies | 4 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | nick_d2 |
| Keywords | Less, JS, server-side, render, cache, live, recompile |

## Links

- npm: https://www.npmjs.com/package/@ndcode/min_js_cache
- Repository: https://git.ndcode.org/public/min_js_cache
- Homepage: https://www.ndcode.org
- npm.io page: https://npm.io/package/@ndcode/min_js_cache

## Dependencies (4)

- [assert](https://npm.io/package/assert.md) ^1.4.1
- [uglify-es](https://npm.io/package/uglify-es.md) ^3.3.9
- [@ndcode/disk_build](https://npm.io/package/@ndcode/disk_build.md) ^0.1.0
- [@ndcode/build_cache](https://npm.io/package/@ndcode/build_cache.md) ^0.1.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.1.0 (latest) — 2018-11-27

## README

# Build Cache wrapper for minifying JavaScript files

An NDCODE project.

## Overview

The `min_js_cache` package exports a single constructor
  `MinJSCache(diag)`
which must be called with the `new` operator. The resulting cache object stores
the `utf-8`-encoded text of JavaScript files loaded from disk and minified.

See the `build_cache`, `disk_build`, and `uglify-es` packages for more
information. The `MinJSCache` object is essentially a wrapper object which
routes the request between these packages, to ensure that the minified
JavaScript text is either retrieved from RAM or minified from a source file as
required.

## Calling API

Suppose one has a `MinJSCache` instance named `mjc`. It behaves somewhat like
an ES6 `Map` object, except that it only has the `mjc.get()` function, because
new objects are added to the cache by attempting to `get` them.

The interface for the `MinJSCache`-provided instance function `mjc.get()` is:

`await mjc.get(key)` &mdash; retrieves the object stored under `key`, where
`key` is the on-disk pathname to a JavaScript file. A `Buffer` object is
returned, containing the `utf-8`-encoded text resulting from running
`uglify-es` on the source file. The pathname and the returned result are cached
for future reuse.

Before returning the cached copy, the existence and modification time of the
JavaScript file on disk is checked to make sure that the cache is up-to-date.
Otherwise, if the file doesn't exist an `ENOENT` exception is thrown, or if the
file exists it is loaded and minified and the cache updated for next time. The
minification is via disk, and skipped if an up-to-date disk result is present.

## About diagnostics

The `diag` argument to the constructor is a `bool`, which if `true` causes
messages to be printed via `console.log()` for all activities except for the
common case of retrieval when the object is already up-to-date. A `diag` value
of `undefined` is treated as `false`, thus it can be omitted in the usual case.

## To be implemented

The `uglify-es` package is called with standard NDCODE options. This is part of
the reason to have `min_js_cache`, so as to provide a consistent interface to
minifiers for JavaScript, CSS, SVG and so on. However, if some control of the
underlying minifier is needed in future, we could add an `options` object to
pass through, in which we'd inject our NDCODE options where not overridden.

It is intended that we will shortly add a timer function (or possibly just a
function that the user should call periodically) to flush built templates from
the cache after a stale time. There is otherwise no way to delete an object
from the cache, except by first deleting it on disk, then trying to `get` it.

## GIT repository

The development version can be cloned, downloaded, or browsed with `gitweb` at:
https://git.ndcode.org/public/min_js_cache.git

## License

All of our NPM packages are MIT licensed, please see LICENSE in the repository.

## Contributions

The caching system is under active development (and is part of a larger project
that is also under development) and thus the API is tentative. Please go ahead
and incorporate the system into your project, or try out our example webserver
built on the system, subject to the caution that the API could change. Please
send us your experience and feedback, and let us know of improvements you make.

Contact: Nick Downing <nick@ndcode.org>

---
_Source: https://npm.io/package/@ndcode/min_js_cache · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
