Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

StaticFile

RobeeeJay edited this page · 3 revisions

This module serves static content such as images, css and js files from a specified directory. It uses the Lactate node module for this purpose, which supports memory caching and gzipping automatically.

new fw.StaticFile({ staticDir: "/static", expireTime: "two days", cacheMem: true, cacheExpire: 60 * 5, cacheCount: 5000, cacheSize: 500 });

staticDir should point to the root directory which contains your static content. expireTime is the cache time for the content, see the Lactate documentation for more details. cacheMem (enabled by default) is whether files should be cached to reduce disk access.

cacheExpire is the amount of time in seconds before a cached item is removed from the cache to free up memory. cacheCount is the maximum number of files the cache will keep track of before old entries are freed. cacheSize is the number of Megabytes the cache is allowed to consume in memory.

Simple Example

var stackFull = new fw.Stack();

stackFull.append(new fw.StaticFile({ staticDir: __dirname + "/static" }));

If the request.url is "/images/dog.jpg" and the file "./static/images/dog.jpg" exists, this will send that file to the client. Otherwise it will continue with the next entry in the Stack.

Something went wrong with that request. Please try again.