Josiah / gulp-cachebust

Generates checksums and renames references to files, useful for cachebusting
30 stars 11 forks source link

added the option of generating checksums using sha1 #15

Closed rubinsh closed 9 years ago

rubinsh commented 9 years ago

Hi,

I had a problem that many times gulp-cachebust generated the same file names (checksums) for my files, even when I was actually doing code changes. I added an option to just use random strings generated with sha1. This makes sure that each time you run gulp-cachebust it will generate different file names. The idea for using sha1 instead of crypto was taken from here: http://stackoverflow.com/a/13254774/203292

This option is disabled by default.

Thanks.

Josiah commented 9 years ago

Thanks for the PR! I'm happy with the random value feature addition, however it would be great if you could implement this a little differently.

Please use crypto.pseudoRandomBytes(size[, callback]) or crypto.randomBytes(size[, callback]) to generate the random value rather than the sha sum of the date. These will give you good enough random values and reduce the chance of collision.

rubinsh commented 9 years ago

Thanks. I've updated the implementation to use crypto.randomBytes. Also - I removed the need of the external sha1 npm package as I found that crypto includes sha1 inside it.

One more thing - I added an MIT license to the package.json - I hope you don't mind :-)

Josiah commented 9 years ago

I'm fine with the implementation and the MIT licence. One change; can we name the optional parameter random rather than useSha1?

It might confuse some people as to the purpose of the parameter otherwise. With that changed I'll be happy to merge.

Thanks for your patience and efforts :)

rubinsh commented 9 years ago

Done - the code was updated. To be honest I wasn't happy with the "useSha1" naming to begin with, but I could not think on something else :-)