铁轨 + Heroku +贾米特

发布于 2024-10-07 06:11:12 字数 370 浏览 4 评论 0原文

我正在努力在 Rails 3 应用程序上安装 Jammit,然后部署到 Heroku。

我安装了 Jammit Gem,并配置了 assets.yml 就可以了,它可以在开发环境中运行。但是当我推送到heroku时,文件被404'ing。

Jammit 的使用说明说:“您可以在 Rakefile 和其他脚本中轻松使用 Jammit:

require 'jammit'
Jammit.package!

我不了解它的工作原理和方式。在我的站点命令中运行 Jammit(就像在 Mac 上一样)会产生未找到的命令。

任何 Jammit 用户都可以帮助我了解如何使用 Jammit 进行生产?

谢谢

I'm working to install Jammit on my Rails 3 app and then to deploy to Heroku.

I installed the Jammit Gem, and configured assets.yml just fine, it works on dev. But when I pushed to heroku, the files were 404'ing.

Jammit's Usage instructions say: "You can easily use Jammit within your Rakefile, and other scripts:

require 'jammit'
Jammit.package!

I'm not following where/how that works. Running Jammit in my sites command like on the Mac yields a command not found.

Any Jammit users able to help me understand how to move to production with Jammit?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

自此以后,行同陌路 2024-10-14 06:11:12

我在 Rails 3.0.7 应用程序上使用 jammit,在 Heroku 上,

gem "jammit", :git => "git://github.com/documentcloud/jammit.git"

我在 rake 文件中使用了 jammit,以便在提交/部署之前打包资产,

desc 'jammit'
  task :jam  => :environment do
  require 'jammit'
  Jammit.package!
end

并且在 .git/hooks/pre-commit 中,因此它是自动完成

echo "jamming it"
rake jam
git add public/assets/*
git add public/javascripts/*

的默认情况下,Heroku 上的过期时间仅为 12 小时,为了增加它(因为我有一个我有信心的缓存清除方案),我将其放入 config/initializers/heroku.rb 中

module Heroku
  class StaticAssetsMiddleware
    def cache_static_asset(reply)
      return reply unless can_cache?(reply)
      status, headers, response = reply        
      headers["Expires"] = CGI.rfc1123_date(11.months.from_now)
      build_new_reply(status, headers, response)
    end
  end
end

以减少 Heroku Rails 服务器上的负载,我还在 CloudFlare 使用免费帐户,它提供了一个轻量级的反向代理/cdn,具有一些不错的分析功能和安全功能。

当我开始缓存常见内容时,这件事真的会让人尖叫!

I'm using jammit on a Rails 3.0.7 app, on Heroku

gem "jammit", :git => "git://github.com/documentcloud/jammit.git"

I have this in a rake file, to package up the assets before I commit/deploy

desc 'jammit'
  task :jam  => :environment do
  require 'jammit'
  Jammit.package!
end

And this in .git/hooks/pre-commit so it is done automatically

echo "jamming it"
rake jam
git add public/assets/*
git add public/javascripts/*

By default, the expires time on Heroku was only 12hrs, to increase it (because I have a cache-busting scheme that I am confident in) I put this in config/initializers/heroku.rb

module Heroku
  class StaticAssetsMiddleware
    def cache_static_asset(reply)
      return reply unless can_cache?(reply)
      status, headers, response = reply        
      headers["Expires"] = CGI.rfc1123_date(11.months.from_now)
      build_new_reply(status, headers, response)
    end
  end
end

To decrease the load on my Heroku Rails server, I am also using a free account at CloudFlare which provides a lightweight, reverse-proxy/cdn, with some decent analytics and security features.

When I get around to caching common content, this thing is really gonna scream!

守不住的情 2024-10-14 06:11:12

您可以像我一样,使用 jammit force 打包您的资产,将所有内容上传到 s3 并在 Rails 中定义资产主机。这样做的另一个好处是可以让您的 slug 更小、响应更快,因为您可以将公共目录添加到 .slugignore 。

或者,由于只读文件系统,您需要弄清楚如何使 heroku 版本正常工作。

You could, as I do, use jammit force to pack your assets, upload everything to s3 and define an asset host(s) in rails. This has the added advantage of keeping your slug smaller and more responsive as you can add your public directory to .slugignore .

Alternatively you'll need to work out how to make the heroku version work due to the read only file system.

最笨的告白 2024-10-14 06:11:12

您还可以使用 git 预提交挂钩来确保您的资产在推送到 heroku(或任何服务器)之前已打包。有关示例,请参阅 https://gist.github.com/862102。您可以将该文件复制到项目目录中的 .git/hooks/pre-commit 中。

You can also use a git pre-commit hook to ensure your assets are packaged prior to pushing to heroku (or any server). See https://gist.github.com/862102 for an example. You can copy that file to .git/hooks/pre-commit in your project directory.

愁以何悠 2024-10-14 06:11:12

Heroku 有一个只读文件系统,因此 Jammit 无法实际存储压缩和缩小的 CSS/JS 文件。

这是一篇关于 Heroku 上资产打包挑战的非常好的文章: http://jimmycuadra.com/posts/the-challenge-of-asset-packaging-on-heroku

Heroku has a read-only file system, so Jammit is unable to actually store compressed and minified CSS/JS files.

Here is a very good article on the challenge of asset packaging on heroku: http://jimmycuadra.com/posts/the-challenge-of-asset-packaging-on-heroku

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文