<commit_before># Cache Manifest Middleware #

This [connect](https://github.com/senchalabs/connect)/[express](http://expressjs.com/) middleware component is intended to make development of HTML5 offline apps easier.
When using the offline cache.manifest, the browser will not request new site resources unless the manifest file itself is updated.
By dynamically generating the cache manifest file and marking it with a last modified timestamp, it is no longer necessary to make manual updates.
By observing a set of files and directories for changes, this can be accomplished efficiently.

This is intended for use in development only, as a deployed application ought not need such frequent change monitoring.
During development, you may also want to use some manner of application cache monitoring such as [AppCache Nanny](https://github.com/gr2m/appcache-nanny) or <https://jonathanstark.com/blog/debugging-html-5-offline-application-cache>.

## Features ##

Freely mix files and directories.
Separate file path mappings and url mappings.
No polling and no filesystem access when serving result. All changes are triggered by observing the filesystem.
Ability to add custom ignore or rewrite patterns.
Sends no-cache header.

## Installation ##

    npm install cache-manifest-middleware

## Usage ##

    var express = require('express');
    var manifest = require('cache-manifest-middleware');

    var app = express();

    app.use(manifest.nocache);
    app.get('/cache.manifest', manifest.generator(['site']);

    app.use(express.static('site'));

    app.listen(8000);

## License ##

MIT<commit_msg>Expanding documentation<commit_after># Cache Manifest Middleware #

This [connect](https://github.com/senchalabs/connect)/[express](http://expressjs.com/) middleware component is intended to make development of HTML5 offline apps easier.

When using an offline cache.manifest, the browser will not request new versions of site resources unless the manifest file itself is updated.
Dynamically generating the cache manifest file and marking it with a last modified timestamp can simplify the development process.

This can be accomplished efficiently by observing a set of files and directories for changes and serving manifest directly from memory.
This monitoring updates in realtime as a part of the same node process as your server and can watch multiple folders recursively for modifications, creations, and deletions.

This is intended for use during development only.
A deployed application ought not need such frequent change monitoring.
You may also want to use some manner of application cache event monitoring such as [AppCache Nanny](https://github.com/gr2m/appcache-nanny) or <https://jonathanstark.com/blog/debugging-html-5-offline-application-cache>.
Finally, Cache-Control headers should probably be sent along with all resources served so as to avoid conflicts between the Offline Cache and regular HTTP caching mechanisms.

## Installation ##

    npm install cache-manifest-middleware

## Usage ##

There are two arguments to the manifest generator.
The first argument is an array of pathes to watch, the second optional argument is an object containging additional parameters.

Paths looks like:

Options include:


## Example ##

An example server using express and serving static content out of two different locations

    var express = require('express');
    var manifest = require('cache-manifest-middleware');

    var app = express();

    //Set Cache-Control: no-cache on all files served during development
    app.use(function(req, res, next) {
      res.set('Cache-Control', 'no-cache');
      next();
    });

    app.get('/cache.manifest', manifest([
      { file: 'transpiler_output', url: '/js' },
      { file: 'site', url: '/' }
    ]);

    app.use(express.static('site'));
    app.use('/js', express.static('transpiler_output'));

    app.listen(8000);

    //TODO: test this sample code

## Tests ##

Run the [Mocha](https://mochajs.org/)-based tests with `npm test`.

## License ##

MIT
{'fraction_non_alphanumeric': 0.08462282398452611, 'fraction_numerical': 0.0033849129593810446, 'mean_word_length': 3.832943925233645, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5840796', 'n_tokens_mistral': 1112, 'n_tokens_neox': 996, 'n_words': 453}