├── .editorconfig ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── IMPLEMENTATION-EXAMPLE.md ├── IMPLEMENTATIONS.md ├── LICENSE ├── README.md ├── index.js ├── package.json └── test └── main.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = tab 6 | end_of_line = lf 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | coverage/ 2 | node_modules/ 3 | npm-debug.log 4 | *.sublime-* 5 | .idea/ 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" 4 | - "0.12" 5 | - "4" 6 | - "5" 7 | - "6" 8 | script: "npm run test-travis" 9 | after_script: "npm i coveralls@2 && cat coverage/lcov.info | coveralls" 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 1.0.0 The Promised Hashing 4 | 5 | ### Breaking changes 6 | 7 | - The `config` method has been removed, you can now pass a configuration options object in the `bust()` call. See the [docs](https://github.com/UltCombo/gulp-buster/#syntax) for details. 8 | - Removed the undocumented experimental `mode` option, use the new `transform` option instead. 9 | - Removed the undocumented `hashes` method. 10 | 11 | ### Patch releases 12 | 13 | - **1.0.1**: Fixed a bug in the crypto hashing logic that would give wrong hash results sometimes, mainly when hashing binary files. Also added official support for Node.js versions 0.12, 4, 5 and 6! (in addition to version 0.10 which was already supported) 14 | - **1.0.2**: Updated dependencies and cleaned up the code style. 15 | 16 | ### New features 17 | 18 | - Configuration options: added new `formatter` and `transform` options, added support for `algo` as a function and negative `length`. See the [docs](https://github.com/UltCombo/gulp-buster/#parameters) for details. 19 | - All of the configuration options which accept a function can be run asynchronously by returning a promise. 20 | - Added type validation for configuration options. 21 | 22 | ## 0.2.0 Multidimensional Configurable Hashing Abyss 23 | 24 | - `fileName` parameter is now optional and defaults to `busters.json`. 25 | - Allow multiple different output files in the same script (hashes are grouped by output filename). 26 | - Added `.config()` method to allow customizing the hashing algorithm, hash length and default output filename. 27 | 28 | ### Patch releases 29 | 30 | - **0.2.1**: Readme: Fixed miscellaneous typos, including config sample. 31 | - **0.2.2**: Fixed crash when piping an empty buffer stream into gulp-buster. Many documentation improvements: added cache busting explanation, improved syntax and architecture documentation, added 3rd-party implementations listing and contributing guide. 32 | 33 | ## 0.1.0 Bustering Gulpness 34 | 35 | - Initial release. 36 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | See [Ult Foundation Contributor's Guide](https://github.com/UltFoundation/Ultiomatic.js/blob/master/CONTRIBUTING.md). 2 | -------------------------------------------------------------------------------- /IMPLEMENTATION-EXAMPLE.md: -------------------------------------------------------------------------------- 1 | # Implementation examples 2 | 3 | These examples explain the basic logic necessary to implement gulp-buster into your application. 4 | 5 | ## Node.js + Jade 6 | 7 | **asset-loader.js** 8 | ```js 9 | var busters = require('path/to/busters.json'); 10 | module.exports = function(path) { 11 | return path + (busters[path] ? '?' + busters[path] : ''); 12 | }; 13 | ``` 14 | 15 | Then when outputting cache-busted file paths, simply call the asset loader passing the (relative to project root) file path. Example with Express and Jade: 16 | 17 | ```jade 18 | script(src=fooSrc) 19 | ``` 20 | 21 | ```js 22 | var asset = require('./asset-loader.js'); 23 | res.render('view', { fooSrc: '/' + asset('js/min/foo.min.js') }, function(err, html) { 24 | // ... 25 | }); 26 | ``` 27 | 28 | As you can see, the gulp-buster `busters.json`'s paths are relative to project root without the leading slash, so we manually prepend a `/` to the cache-busted URL. This works nicely if your project root corresponds to the web server root. Otherwise, you will have to prepend the correct base URL. The optimal way would be to dynamically retrieve your app's base URL, specially as the project path relative to the web server root may differ between production and local development environments (e.g. it is a common scenario to have the project run at `/` in the production server and at `/myProject/` in local development). 29 | 30 | ## Client-side 31 | 32 | There are many ways to implement this in the front-end as well. If your project uses an AMD loader such as Require.js, you can map the modules to their cache-busted URLs in the config. Even without any loader, it is possible to `document.write` the scripts as follows: 33 | 34 | ```js 35 | ['app', 'services', 'controllers', 'filters', 'directives'].forEach(function(s) { 36 | document.write('