npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-hashres

v0.4.1

Published

Hashes your js and css files and rename the <script> and <link> declarations that refer to them in your html/php/etc files.

Downloads

5,921

Readme

grunt-hashres has been updated to Grunt 0.4. if you're still using Grunt 0.3.x go to old version documentation

grunt-hashres

Build Status

Hashes your js and css files and rename the <script> and <link> declarations that refer to them in your html/php/etc files.

Getting Started

Install this grunt plugin next to your project's Gruntfile.js with: npm install grunt-hashres

Then add this line to your project's grunt.js gruntfile:

grunt.loadNpmTasks('grunt-hashres');

Documentation

Add the following to your Gruntfile.js file, inside the initConfig function:

hashres: {
  // Global options
  options: {
    // Optional. Encoding used to read/write files. Default value 'utf8'
    encoding: 'utf8',
    // Optional. Format used to name the files specified in 'files' property.
    // Default value: '${hash}.${name}.cache.${ext}'
    fileNameFormat: '${hash}.${name}.cache.${ext}',
    // Optional. Should files be renamed or only alter the references to the files
    // Use it with '${name}.${ext}?${hash} to get perfect caching without renaming your files
    // Default value: true
    renameFiles: true
  },
  // hashres is a multitask. Here 'prod' is the name of the subtask. You can have as many as you want.
  prod: {
    // Specific options, override the global ones
    options: {
      // You can override encoding, fileNameFormat or renameFiles
    },
    // Files to hash
    src: [
      // WARNING: These files will be renamed!
      'dist/prod/scripts/my-compressed-and-minified-scripts.js',
      'dist/prod/styles/my-compressed-and-minified-styles.css'],
    // File that refers to above files and needs to be updated with the hashed name
    dest: 'dist/prod/home.php',
  }
}

Recommended workflow

grunt-hashres, as a general rule, should be run when you're going to release your code. Ideally, you should create a stage folder where you'll copy your html, minified js and css and all your resources. And then, on this clean copy, hash the resource names.

Alternative workflow

Due to popular demand, the task support to update references that where already hashed. This means, that you won't need to create a stage folder before running grunt-hashres. See #26 and #29 for more info.

Heads up

If you have upgraded from Grunt 0.3 version: 'files' and 'out' config properties have been replaced by 'src' and 'dest'

Properties

  • src: A single file expression or an array of file expressions. Something like myscripts/*.js would be valid.
  • dest: The file expression(s) that refer to the hashed files and that will be updated with the new names. You can update more than one file specifying an array of output files: [out/fileOne.html, out/fileTwo.html]
  • encoding: Encoding used to read and write files. Using utf8 by default.
  • fileNameFormat: The files specified in property files will be renamed according to the pattern specified in this property. The following variables are allowed:
    • ${hash}: the first 8 digits of the md5 of the file.
    • ${name}: the original name of the file.
    • ${ext}: the original extension of the file.
  • renameFiles: Rename the files or leave them in place and only alter the references to them in out. Defaults to true

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Release History

  • 13/02/14 - 0.4.1: Bugfix #32: Now it works when you try to substitute bar.js and foobar.js in the same go. Thanks to crodas
  • 24/01/14 - 0.4.0: Due to popular demand (see #26, #29, and more) grunt-hashres now support to run multiple times the hashing without creating a clean copy of the files to hash. Thanks to jrduncans and ajaybc for their effort.
  • 17/11/14 - 0.3.4: Bugfix #18: Fixed special character test that doesn't work on windows.
  • 07/11/13 - 0.3.3: Bugfix #16: Renaming files with special characters. Thanks to crodas.
  • 14/05/13 - 0.3.2: Bugfix #8: Replace all ocurrences. Thanks to kleinsch.
  • 20/02/13 - 0.3.0: Update to Grunt 0.4. Check out the documentation because some configuration properties have changed.
  • 19/11/12 - 0.2.1: Optional File Renaming. Thanks to raphaeleidus.
  • 14/11/12 - 0.1.5: Feature request #1: fileNameFormat property added.
  • 02/11/12 - 0.1.3: First working release.

License

Copyright (c) 2013 Luismahou Licensed under the MIT license.