What kind of caching do you want?  This is a complicated issue.  And
are you also talking about conditional http requests (Etag,
timestamps, 304 responses)?  What about range request support?

A simple filter in front of any off-the-shelf static file server
should five you 95% of what you want.

var staticHandler = require('creationix').static("/", __dirname);
function (req, res, next) {
  if (!req.uri) { req.uri = urlParse(req.url); } // parse the url if
it hasn't been parsed by another middleware
  if (req.uri.pathname === "/app.js" ||
!req.uri.pathname.match(/\.js$/)) return next();
  staticHandler(req, res, next);
}

Then you'll mount / -> / but only if it ends in ".js" and is not app.js.

If you don't mind caching your files in memory, then just read the
files to ram (either at startup or on demand) and watch the files for
changes (if you want to pick up changes) to invalidate your cache.

There may be an existing module that does everything you want out of
the box, but most likely, nothing is 100% what you want.  Just build
what you want using simple modules (mime or my simple-mime, for
example to get mime type) and code you type.  Don't fall into the trap
of using a large library that only does 50% of what you need and then
spend more time tweaking/hacking it than you would spend just building
what you want from scratch.

On Fri, Aug 3, 2012 at 9:46 AM, Felix E. Klee <felix.k...@inka.de> wrote:
> What is a good module to serve some static (JavaScript) files (including
> caching and compression)?
>
> Desired mapping of files to URLs:
>
>   scripts/*.js -> http://example.com/scripts/*.js (only for development)
>   xyz.js       -> http://example.com/xyz.js
>   app.js       -> not served (of course)
>   package.json -> not served (of course)
>   ...
>
> That's it. There is no public directory in my app.
>
> What I already looked at:
>
> * node-static: only allows specification of a public directory which is
>   mapped to the root of <http://example.com/>. As you can see above,
>   this is not what I want.
>
> * connect: will not do caching anymore ("connect.staticCache() is
>   deprecated and will be removed in 3.0 use varnish or similar reverse
>   proxy caches")
>
> By the way, I plan to deploy to Nodejitsu. Does anyone know whether they
> do automatic caching?
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: 
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nodejs@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to