Rails 3.1 Asset Pipeline - turn off image asset fingerprinting on Heroku?

半城伤御伤魂 提交于 2019-12-23 15:33:38

问题


Because a jQuery plugin I use in my application has direct references to images, I'm trying to turn off asset fingerprinting.

So I set config.assets.digest = false in my production.rb, but now none of my image references work at all. /assets/foo.png just returns a blank response.

I really don't want to alter the jQuery plugin's code and add erb image helpers, but I'm not sure what else to do. And frankly, the asset fingerprinting for images seems to be much more trouble than it's worth.

Does anybody have any insight?

Thanks!


回答1:


If you are using a large plugin, like ckeditor, then your only real option is to move that plugin into the public directory.

For smaller plugins you can move their images into the correct asset path. For example if your plugin references images/icon.jpg under the plugin folder this would need to be moved to something like app/assets/images/plugin_name/icon.png and then referenced in the plugin with <%= asset_tag('plugin_name/icon.png') %>.

The pipeline IS worth it. Not using digests in production pretty much negates the point of using it at all, which is to set far-future headers so that the asset gets cached somewhere.

If you are set on removing digests then you must precompile the assets (so that Sprockets does not serve them with far-future headers), and make sure no headers are set on the server.




回答2:


Someone made a gem for this purpose:

https://github.com/spohlenz/digestion

The asset pipeline is a great new component of Rails 3.1. However it has a feature known as fingerprinting that makes it impossible to properly incorporate many popular JavaScript libraries (including TinyMCE, CKEditor and FancyZoom to name just a few) into the asset pipeline.

This gem patches the asset pipeline to allow these libraries to be used, by disabling the fingerprinting functionality for specific files or paths.



来源:https://stackoverflow.com/questions/7375810/rails-3-1-asset-pipeline-turn-off-image-asset-fingerprinting-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!