Coder Social home page Coder Social logo

oresoftware / express.fs.cache Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 99 KB

Cache and serve static assets from memory using Express middleware.

License: MIT License

Shell 21.53% TypeScript 58.36% JavaScript 20.11%
fs express-middleware expressjs nodejs npm-package

express.fs.cache's Introduction

Travis Build Status
CircleCI Build Status
Latest NPM version

@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

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().

express.fs.cache's People

Contributors

oresoftware avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

express.fs.cache's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.