Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
New version and readme updates
  • Loading branch information
download13 committed Mar 31, 2014
1 parent e5671bb commit d708d66
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
37 changes: 14 additions & 23 deletions README.md
@@ -1,38 +1,29 @@
ex-static
=========

**WARNING: DO NOT USE ON LARGE FILES!**
`ex-static` keeps all file data in memory and so is not recommended for files larger than a megabyte (unless you have a lot of spare RAM).
Now also watches files for changes and reloads them when needed.
Serves files. It's pretty fast.

### To use:
```javascript
var http = require('http');
var static = require('ex-static');

var staticFiles = [
var files = [
{url: '/', path: 'static/index.html'},
{url: '/test.jar', path: 'static/test.jar', type: 'application/java-archive', cache: -1, compress: true}
{url: '/test.jar', path: 'static/test.jar', type: 'application/java-archive', cache: 300000, compress: true}
];

http.createServer(staticFiles).listen(80);
http.createServer(static(files)).listen(80);
```

The `cache` parameter sets the number of seconds on the `Cache-Control: max-age` header. Using -1 sets a very large value while using 0 sets no header.
* `cache` - Sets the number of seconds on the `Cache-Control: max-age` header. Using 0 sets no header.
* `type` - Used to specify a `Content-Type`, or override the default type associated with the file extension.
* `compress` - Set whether we should use compression. Small files have it on by default.
* `stream` - True if the file should be streamed to the client, false if it should be written in one chunk. Defaults to true for small files.
* `path` - The local file path where the file can be found.
* `url` - The url where the file should be served.


All files have `ETag` values that are the MD5 hashes of their contents.
`type` is used to specify a `Content-Type`, or override the default type associated with the file extension.
All `text/*` files are compressed with `gzip` for browsers that support it. To override the default compression setting for a file, use the `compress` parameter.

`ex-static` also supports automatic revving of HTML files.
Any instance of the string `{rev}` in an HTML file will be replaced with a timestamp when the static server starts up.
This is useful for ensuring that users have the latest version of a file even if the `cache` option is enabled.
### Example:
```html
<!DOCTYPE html>
<html>
<head>
<script src="/js/main.js?{rev}"></script>
</head>
<body></body>
</html>
```

Small files are compressed with gzip for browsers that support it. To override the default compression setting for a file, use the `compress` parameter.
9 changes: 4 additions & 5 deletions package.json
@@ -1,22 +1,21 @@
{
"name": "ex-static",
"description": "Fast, static file server middleware with built-in revving",
"version": "0.3.0",
"version": "0.4.0",
"author": "download <download333@gmail.com>",
"main": "static",
"scripts": {
"test": "moka"
"test": "mocha"
},
"repository": {
"type": "git",
"url": "https://github.com/download13/static"
"url": "https://github.com/download13/ex-static"
},
"dependencies": {
"mime": "1.x.x"
},
"devDependencies": {
"moka": "*",
"expect.js": "*"
"mocha": "*"
},
"engine": {
"node": "*"
Expand Down

0 comments on commit d708d66

Please sign in to comment.