Skip to content

gowthamravichandran/express-asset-versions

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-asset-versions NPM version

An express.js middleware and helper to prepend your static assets with a version string.

Usage

Setup

$ npm install express-asset-versions
var express = require('express')
  , assets = require('express-asset-versions')
  , app = express();

var assetPath = path.join(__dirname, 'public');
app.use('/public', express.static(assetPath));
app.use(assets('/public', assetPath));

app.listen(3000);

Templates

// EJS
<link rel="stylesheet" href="<%= asset('css/stylesheet.css') %>" />
// Jade
link(rel='stylesheet', href=asset('css/stylesheet.css'))
// Swig
<link rel="stylesheet" href="{{ asset('css/stylesheet.css') }}" />

// Result:
<link rel="stylesheet" href="/public/css/stylesheet.css?1f05a21474" />

The asset() helper takes an optional second parameter to define a file used in production (NODE_ENV=production):

<link rel="stylesheet" href="<%= asset('css/stylesheet.css', 'css/stylesheet.min.css') %>" />

// Result:
<link rel="stylesheet" href="/public/css/stylesheet.css?1f05a21474" />     // NODE_ENV=development
<link rel="stylesheet" href="/public/css/stylesheet.min.css?73d57ce89a" /> // NODE_ENV=production

About

Simple versioning for assets in express.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%