grunt-filerev icon indicating copy to clipboard operation
grunt-filerev copied to clipboard

Add option to store revision as a query param instead of renaming the files

Open burnedikt opened this issue 10 years ago • 7 comments
trafficstars

What is it good for?

This feature offers a slightly different functionality for the plugin which is optional and does not affect the core functionality.

Instead of renaming files and including the revision hash in the filename, the new option useQueryParam allows to not change the filename and attach the revision number as a query parameter when referencing the file, instead.

Why?

This can help in certain use cases where it is desirable to bust caches by including revision information, but it is not possible for infrastructural reasons (e.g. other applications referring to the same files) to change the complete filename on every change.

Compatibility

While the filenames won't change, the grunt.filerev.summary will hold information about the new and revision-specific url / query parameter for the respective file. That way, other tasks like grunt-usemin will still work seemlessly when replacing references to the revved files.

Example
// Renames files for browser caching purposes
filerev: {
  dist: {
    src: 'styles/{,*/}*.css',
    dest: 'bar',
    options: {
      useQueryParam: true
    }
  }
}

That way, e.g. main.a1b2c3.css would become main.css?rev=a1b2c3 and the grunt.filerev.summary will look like:

{
  ...,
  "main.css": "main.css?rev=a1b2c3",
  ...
}

burnedikt avatar Jun 05 '15 19:06 burnedikt

I doubt this will land as the plugin doesn't currently have any active maintainer, and I would personally rather see more code and options removed than added. You're probably better off trying to get this into another plugin, fork this one, or create your own.

sindresorhus avatar Jun 05 '15 19:06 sindresorhus

you're probably right but it doesn't really matter to me. I just had this kind of use case on one of our legacy projects built on grunt and I just felt like sharing it - maybe someone else will face the same question / issue again in the future and can benefit from the simple adjustments I made.

burnedikt avatar Jun 05 '15 19:06 burnedikt

Doesn't putting it as a query param automatically invalidate it in the browser cache for some browsers?

eddiemonge avatar Jun 05 '15 20:06 eddiemonge

I actually do not know of any major browser in which we still face this issue (automatic invalidation when using query params), though I read about it in some older posts. Additionally, there are some proxies, like e.g. squid, that seem to treat any resources referenced to with query params as dynamic content and decide to never cache them (http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/). However, this post is also almost 7 years old and very likely to contain outdated information.

Personal opinion: Even if there are some browsers or proxies that fail to cache resources with query params in the url, the majority of browsers and proxies seems to have no problems with caching. While it most certainly isn't the best solution for revving files, there are use cases where this feature might be desirable.

burnedikt avatar Jun 07 '15 14:06 burnedikt

What's the consensus here? Do we close the PR?

I doubt this will land as the plugin doesn't currently have any active maintainer, and I would personally rather see more code and options removed than added. You're probably better off trying to get this into another plugin, fork this one, or create your own.

:+1:

arthurvr avatar Jul 02 '15 09:07 arthurvr

it would be a fix for https://github.com/yeoman/grunt-filerev/issues/85. but im still not sure its a good idea. maybe though.

eddiemonge avatar Jul 02 '15 16:07 eddiemonge

Hi I am also using filerev, but require to cache with query parameters but the present code with npm does not support it. what happens if we add that support?

saikrishnaradarapu avatar May 05 '17 12:05 saikrishnaradarapu