Skip to content

Commit 25dda34

Browse files
committed
Updated docs
1 parent 54ef556 commit 25dda34

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

README.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
#node-static-asset
22

33
node-static-asset is a static asset manager for Node.JS, designed for Express.
4-
This project aims to solve all application deployment problems. No thinking
5-
required.
4+
This project aims to solve the problem of caching static assets (including
5+
assets like *.js files that might change from time to time).
66

77
## Background
88

9-
Google has a nice article about strong and weak caching. It's worth a quick
9+
Google has a nice article about "strong" and "weak" caching. It's worth a quick
1010
read if you don't know what that means.
1111

1212
https://developers.google.com/speed/docs/best-practices/caching
1313

1414
## Getting Started
1515

16-
node-static-asset allows you to compile, bundle, minify/compress, and deploy
17-
your static assets. The basic idea works like this:
16+
node-static-asset allows you to generate URL fingerprints for static assets in
17+
a way that works for your application.
1818

1919
1. Add the static-asset middleware to your Express stack
20-
2120
```javascript
2221
var staticAsset = require('static-asset');
2322
app.use(staticAsset(__dirname + "/public/") );
2423
```
2524

2625
2. Get URL fingerprints of your static resources using `req.assetFingerprint`
2726
or the `assetFingerprint` view helper function.
28-
2927
```javascript
3028
app.get("/info", function(req, res, next) {
3129
res.type("text/plain").send("The URL fingerprint for jQuery is: " +
@@ -35,7 +33,9 @@ app.get("/info", function(req, res, next) {
3533

3634
The above gives you weak and strong caching for all files served in the /public
3735
directory. But, that's not all; static-asset has many more features that allow
38-
you to customize how files are cached and how to generate URL fingerprints.
36+
you to customize how files are cached and how to generate URL fingerprints. You
37+
can even write your own middleware that minifies JavaScript files, for example,
38+
and use static-asset to serve them to the browser.
3939

4040
## API
4141

@@ -54,11 +54,13 @@ strong caching headers to the response.
5454

5555
**"Cache Strategy" Object** - a "cache strategy" object should implement one or
5656
more of the following methods:
57+
5758
-lastModified(label_or_filename, cb) - a function that accepts a label
5859
or filename and returns its last modified date to the callback.
5960
If a last modified date could not be determined, null is passed to the
6061
callback; otherwise, static-asset *may* use this Date to set the
6162
`Last-Modified` HTTP header when the named resource is served.
63+
6264
-label_or_filename - a label or filename in `path`
6365
-cb - a callback of the form `cb(err, lastModifiedDate)`
6466
-etag(label_or_filename, cb) - Same as lastModified (above), except
@@ -77,6 +79,18 @@ strategy", return a URL fingerprint for the labelled resource, or if no such
7779
label is registered, attempt to locate the specified filename within the `path`
7880
to determine its fingerprint.
7981

82+
**req.assetFingerprint(label, urlFingerprint, cacheInfo)** - Registers a URL
83+
fingerprint for the specified label.
84+
85+
-label - a label identifying the resource
86+
-urlFingerprint - the URL fingerprint for the resource. If a request for this
87+
resource is made, static-asset may add caching headers to the response.
88+
-cacheInfo - an Object containing these properties:
89+
-lastModified - the last modified date of the resource
90+
-etag - the ETag of the resource
91+
-expires - the expiration date of the resource; if not given, the resource
92+
will expire approximately one year in the future. Set to `null` to
93+
disable strong caching headers.
8094

8195
Other middleware on the stack can generate their own URL fingerprints for
8296
static resources and expose them through `req.assetFingerprint`. Like this:
@@ -88,13 +102,6 @@ req.assetFingerprint(javascript_filename, javascript_filename + "?v=" +
88102
stat.mdate.getTime(), {"lastModified": stat.mdate});
89103
```
90104

91-
4. Customize your caching algorithms by overriding the defaults.
92-
93-
```javascript
94-
var staticAsset = require('static-asset');
95-
app.use(staticAsset(__dirname + "/public/") );
96-
```
97-
98105
## Install
99106

100107
`npm install static-asset`

0 commit comments

Comments
 (0)