grunt-cachebust

Append a query string to your assets to bust that cache!

grunt-cachebust

Append a timestamp to your assets to bust that cache!

This plugin requires Grunt.

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-cachebust --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-cachebust');

In your project's Gruntfile, add a section named cachebust to the data object passed into grunt.initConfig().

grunt.initConfig({
  cachebust: {
    options: {
    // Task-specific options go here. 
    },
    your_target: {
    // Target-specific file lists and/or options go here. 
    }
  }
});

Type: String Default value: 'MD5'

A string value that is used denote the type of query string append to asset paths:

  • MD5
  • timestamp
grunt.initConfig({
  cachebust: {
    default_options: {
      files: [
      {
        expand: true,
        cwd: 'dist/',
        src: [
          '**/*.html'
        ],
        dest: 'dist/'
      } 
      ]
    }
  }
});
grunt.initConfig({
  cachebust: {
    custom_options: {
      options: {
        type: 'timestamp'
      },
      files: [
        {
          expand: true,
          cwd: 'dist',
          src: [
            '**/*.html'
          ],
          dest: 'dist/'
        }
      ]
    }
  }
});

To contribute either check the Waffle board or GitHub issues then work away:

  1. Fork it!
  2. Create your feature branch: git checkout -b feature/awesome-feature
  3. Run: npm install for dependencies and npm link for local development
  4. Run: grunt develop to build and watch for changes
  5. Commit your changes: git commit -m 'feat(Project): Adds awesome feature'
  6. Push to the branch: git push origin feature/awesome-feature
  7. Submit a pull request :+1:

Tips:

  • In lieu of a formal styleguide, take care to maintain the existing coding style.
  • Add unit tests for any new or changed functionality.
  • Test your code using Grunt: grunt test
  • Install editorconfig-sublime for Sublime Text to help with consistent code formatting.
  • Commit messages loosely adhere to these guidelines.
  • Versioning adheres to Semver.
  • 2014-11-04 v0.4.0 - Adds support for skipping over (assumed) CDN served assets.
  • 2014-11-04 v0.3.0 - Hashes MD5 based on file contents.
  • 2014-11-03 v0.2.0 - Adds support for MD5 hashing as default, timestamp optional.
  • 2014-11-03 v0.1.0 - Initial release.

Copyright (c) 2014 Daniel Furze.

Licensed under the MIT license: http://danielfurze.mit-license.org