Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 01a466702a
Fetching contributors…

Cannot retrieve contributors at this time

82 lines (43 sloc) 2.11 kB

Express Cachebuster

express-cachebuster provides cross-browser version-control/cache-busting as a dynamic view helper in express.

This was made as an integrated feature of Expressling.

Quick install

  $ npm install express-cachebuster

Usage

Add the following to your express app (e.g. server.js):

  app.configure(function() {
    app.set('public', __dirname + '/public');
  });

  app.dynamicHelpers({
    cacheBuster: require('express-cachebuster');
  });

In your views execute the cacheBuster function and pass your asset's path.

For more options see Goodies.

Note: $ = variable which is automagically returned by express-cachebuster.

EJS

  <%- cacheBuster('/js/mylibs/script.js') %>

Outputs HTML as shown below for development environment:

  <script type='text/javascript' src='/js/mylibs/script.js?v=$currentTimestamp'></script>

...and for production environment:

  <script type='text/javascript' src='/js/mylibs/script.js'></script>

Jade

  != cacheBuster('/stylesheets/style.css')

Outputs HTML as shown below for development environment:

  <link rel='stylesheet' href='/stylesheets/style.css?v=$currentTimestamp'>

...and for production environment:

  <link rel='stylesheet' href='/stylesheets/style.css'>

Goodies

You can pass an array of assets to the middleware:

EJS: <%- cacheBuster(['/stylesheets/style.css', '/stylesheets/ie.css']) %>

Jade: != cacheBuster(['/stylesheets/style.css', '/stylesheets/ie.css'])

Outputs HTML as shown below for development environment:

  <link rel='stylesheet' href='/public/css/style.css?v=$currentTimestamp'>
  <link rel='stylesheet' href='/public/css/ie.css?v=$currentTimestamp'>

.. and for production environment:

  <link rel='stylesheet' href='/public/css/style.css'>
  <link rel='stylesheet' href='/public/css/ie.css'>

Contributors

Butu - butu25@gmail.com - @butu5

License

MIT Licensed

Jump to Line
Something went wrong with that request. Please try again.