百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
N

non-stupid-digest-assets

> 编程语言
开源

修复 Rails 4 资产管道,以生成除摘要资产以外的其他资产

492 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

修复 Rails 4 资产管道,以生成除摘要资产以外的其他资产

Non-stupid non-digest assets in Rails 4

What is it?

In Rails 4, there is no way to by default compile both digest and non-digest assets. This is a pain in the arse for almost everyone developing a Rails 4 app. This gem solves the problem with the minimum possible effort.

How do I install it?

Just put it in your Gemfile

ruby
gem "non-stupid-digest-assets"

If you want to whitelist non-digest assets for only certain files, you can configure a whitelist like this:

ruby
# config/initializers/non_digest_assets.rb

NonStupidDigestAssets.whitelist += [/tinymce\/.*/, "image.png"]

Be sure to give either a regex that will match the right assets or the logical path of the asset in question.

Note that the logical path is what you would provide to asset_url, so for an image at RAILS_ROOT/assets/images/foo.png the logical path is foo.png

But shouldn't I always use the Rails asset helpers anyway?

Yes. But there are some obvious cases where you can't do this:

  • Third party libraries in vendor/assets that need to include e.g. css / images
  • In a static error page, e.g. a 404 page or a 500 page
  • Referencing the assets from outside your rails application

What about other solutions?

sprockets-redirect uses a rack middleware to 302 redirect to the digest asset. This is terrible for performance because it requires 2 HTTP requests, and it also hits your ruby stack. An asset request should be handled by your webserver (e.g. nginx) because that's what it's good at.

This rake task will solve this problem, but requires an extra rake task. It won't work by default with things like capistrano / heroku. And it requires you to manage the code in your app.

Why do I need digest assets at all?

Digests are used for cache busting. Remember that if you use the non-digest assets and serve them with far-future expires headers, you will cause problems with cached assets if the contents ever need to change. You must bear this in mind when using non-digest assets.

Why is this not the default / a config option in Rails 4?

Good question. I think it should be. Complain here

Issues· 16 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言