zeroclipboard / zeroclipboard-rails

ZeroClipboard rails gem
http://zeroclipboard.org/
MIT License
125 stars 36 forks source link

Disable ZeroClipboard's cache busting when using Rails asset digests #37

Closed foobear closed 8 years ago

foobear commented 8 years ago

When using Rails asset digests, ZeroClipboard.swf becomes something like ZeroClipboard-abcd1234ef.swf and is referenced as such through the swfPath config option, set by zeroclipboard-rails.

However, ZeroClipboard also includes its own cache busting mechanism: adding a noCache query param that sends the current timestamp. This is not necessary when using Rails asset digests.

ZeroClipboard offers a config option to disable noCache that we should set to false when using asset digests. Here is a PR for that. :)

If you're uncomfortable with my changes using to_json, this is maybe less invasive:

 //= depend_on_asset "ZeroClipboard.swf"
 ZeroClipboard.config({
+  noCache: <%= Rails.configuration.assets.digest ? 'true' : 'false' %>,
   swfPath: '<%= image_path "ZeroClipboard.swf" %>'
 });
HaNdTriX commented 8 years ago

Thanks for your PR. Looks good to me.

JamesMGreene commented 8 years ago

I'm OK with the changes but I'm going to forewarn you, @foobear, that you may run into issues in certain usage situations because browsers still don't really understand Flash very well....

e.g. https://github.com/zeroclipboard/zeroclipboard/issues/357

foobear commented 8 years ago

@JamesMGreene - Not sure I fully understand the problem. The change should not affect flash vars, but only omit the noCache URL param that would force the browser to reload the .swf file.

When compiling assets, Rails creates specific filenames based on each file's checksum. For version 1.0 of ZeroClipboard.swf that would be something like ZeroClipboard-abc123.swf, while version 1.1 results in ZeroClipboard-def456.swf.

So a changed .swf file would already force cache busting due to its new (generated) filename, and the cacheBust option / noCache param is not necessary and would even force a reload when we know the .swf is the same.