-
Notifications
You must be signed in to change notification settings - Fork 73
Add option to store revision as a query param instead of renaming the files #90
base: master
Are you sure you want to change the base?
Conversation
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. |
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. |
Doesn't putting it as a query param automatically invalidate it in the browser cache for some browsers? |
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. |
What's the consensus here? Do we close the PR?
👍 |
it would be a fix for #85. but im still not sure its a good idea. maybe though. |
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? |
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 likegrunt-usemin
will still work seemlessly when replacing references to the revved files.Example
That way, e.g.
main.a1b2c3.css
would becomemain.css?rev=a1b2c3
and thegrunt.filerev.summary
will look like: