Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

burnedikt
Copy link

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",
  ...
}

@sindresorhus
Copy link
Member

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.

@burnedikt
Copy link
Author

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.

@eddiemonge
Copy link
Member

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

@burnedikt
Copy link
Author

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.

@arthurvr
Copy link
Member

arthurvr commented Jul 2, 2015

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.

👍

@eddiemonge
Copy link
Member

it would be a fix for #85. but im still not sure its a good idea. maybe though.

@saikrishnaradarapu
Copy link

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants