Giter Site home page Giter Site logo

express-cachebuster's Introduction

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][1]. [1]: http://expressling.com

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 src='/js/mylibs/script.js?v=$currentTimestamp' type='text/javascript'></script>

… and for production environment:

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

Jade

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

Outputs HTML as shown below for development environment:

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

… and for production environment:

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

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 href='/stylesheets/style.css?v=$currentTimestamp' rel='stylesheet'>
  <link href='/stylesheets/ie.css?v=$currentTimestamp' rel='stylesheet'>

… and for production environment:

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

You can pass an object as the second parameter representing attributes and their values to add to the generated tag:

  cacheBuster('/scripts/require.js', {'data-message': 'Hello world', 'data-main': '/app/main.js'})

which outputs the following HTML:

  <script data-main='/app/main.js' data-message='Hello world' src='/scripts/require.js' type='text/javascript'></script>

Contributors

David Murdoch - [email protected] - @davidmurdoch Butu - [email protected] - @butu5

License

MIT Licensed

express-cachebuster's People

Contributors

jmervine avatar niftylettuce avatar proful avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

express-cachebuster's Issues

Dependent on mime

Seems like this is dependent on the 'mime' package. I had to install it separately to get my app to run with cachebuster.

Node 0.8.x not supported?

In package.json there the following directive:

"engines": { "node":">= 0.5.0 < 0.7.0" }

why node 0.8 is not supported?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.