https://github.com/oresoftware/express.fs.cache
Cache and serve static assets from memory using Express middleware.
https://github.com/oresoftware/express.fs.cache
express-middleware expressjs fs nodejs npm-package
Last synced: 11 months ago
JSON representation
Cache and serve static assets from memory using Express middleware.
- Host: GitHub
- URL: https://github.com/oresoftware/express.fs.cache
- Owner: ORESoftware
- License: mit
- Created: 2018-05-12T00:11:18.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-01-20T20:14:29.000Z (about 6 years ago)
- Last Synced: 2023-03-02T00:26:02.439Z (almost 3 years ago)
- Topics: express-middleware, expressjs, fs, nodejs, npm-package
- Language: TypeScript
- Homepage:
- Size: 96.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# @oresoftware/fast.static
> Use Express middleware to cache and serve static assets from memory, not disk.
> A good optimization for production servers.
> Will tell you how big the cache is, in bytes, in memory.
### Installation:
>
> `npm i @oresoftware/fast.static`
>
## Example
```js
import * as express from 'express';
import statikCache from '@oresoftware/fast.static';
if(process.env.in_production === 'yes'){
app.use('/public', statikCache('public'));
}
app.use('/public', express.static('public'));
```
# In Development
In development, if you re-load the server on changes to front-end static assets, then you don't really
need the env variable check. Otherwise, I would only use this in the production.
If the files are in the cache, they will get served by the cache.
Given the above code, we would cache all `.js`, `.html`, `.css` files in the public directory.
The cached files would be served from an in-memory cache.
If for some reason, a file is not in the cache, then the regular express static middleware would
pick up where we left off.
This middleware never calls `next(err)`, only `next()`.