资产出现问题 - 本地每个页面加载时间超过 1.5 分钟

发布于 2024-12-12 01:24:54 字数 1371 浏览 0 评论 0原文

自从我转移到 active_admin 后,我的本地服务器需要 1.5 分钟以上才能加载每个页面。我肯定做错了什么。

Development.rb

config.assets.compress = true; config.assets.debug = true; config.assets.compile = false; config.assets.digest = false

Production.rb

config.assets.compress = true; config.assets.compile = true; config.assets.digest = true; config.assets.precompile += ['active_admin.js', 'active_admin.css']

请注意,编译在生产中是正确的,因为活动管理在其他情况下不起作用。

assets 文件夹

--javascripts

-----active_admin.js

加载其文件

-----application.js 从 //= require_tree ./myfolder/ -----myfolder

---- ------1.js

----------2.js

----------....

--stylesheets

-----active_admin.css.scss

- ----application.css.scss 从 *= require_tree ./myfolder/

-----myfolder

----------1.css.scss

加载其文件----------2.css.scss

----------....

日志

似乎是因为每个资源的加载时间文件。我只列出第一个和最后一个。两者的时间差为1.5分钟。

于 2011 年 10 月 24 日开始 GET “/assets/jquery.js?body=1” for 127.0.0.1 18:19:41 +0530 服务资产 /jquery.js - 200 OK (4ms)

开始 GET "/assets/myfolder/vertical_menu.css?body=1" for 127.0.0.1 at 2011-10-24 18:21:04 +0530 服务资产 /myfolder/vertical_menu.css - 200 OK (2ms)

我做错了什么?

Since I moved to active_admin my local server takes over 1.5 minutes to load each and every page. I'm surely doing something wrong.

Development.rb

config.assets.compress = true; config.assets.debug = true; config.assets.compile = false; config.assets.digest = false

Production.rb

config.assets.compress = true; config.assets.compile = true; config.assets.digest = true; config.assets.precompile += ['active_admin.js', 'active_admin.css']

Note the compile is true in production because active admin does not work other wise.

assets folder

--javascripts

-----active_admin.js

-----application.js loads its files from //= require_tree ./myfolder/

-----myfolder

----------1.js

----------2.js

----------....

--stylesheets

-----active_admin.css.scss

-----application.css.scss loads its files from *= require_tree ./myfolder/

-----myfolder

----------1.css.scss

----------2.css.scss

----------....

Logs

Seems to be because of the load time of each of the assets files. I m listing only the first and last. The time difference between the two is 1.5 minutes.

Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2011-10-24 18:19:41 +0530 Served asset /jquery.js - 200 OK (4ms)

Started GET "/assets/myfolder/vertical_menu.css?body=1" for 127.0.0.1 at 2011-10-24 18:21:04 +0530 Served asset /myfolder/vertical_menu.css - 200 OK (2ms)

WHAT AM I DOING WRONG?

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

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

发布评论

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

评论(3

唱一曲作罢 2024-12-19 01:24:55

在你的 Production.rb 中,你可以尝试添加

config.assets.compile = false

然后运行

bundle exec rake assets:precompile

​​这应该在你的 public/assets 目录中创建 application-somemd5.js 和 application-someothermd5.css ,并且在生产模式下,将提供这些预编译的资产,而不是重新编译资产每个页面加载的管道。

编辑:

实际上,我认为您可能需要将 rake 命令设置为如下所示:

bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile

RAILS_GROUPS 部分取决于您的 Gemfile 设置方式。如果您有这样的部分,您将需要它:

group :assets do
  gem 'jquery-rails'
  gem 'sass-rails'
  .... etc
end

In your production.rb can you try adding

config.assets.compile = false

And then run

bundle exec rake assets:precompile

This should create application-somemd5.js and application-someothermd5.css in your public/assets directory, and in production mode those precompiled assets will be served rather than re-compiling the asset pipeline with each page load.

EDIT:

Actually, I think you may need to make the rake command something like this:

bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile

The RAILS_GROUPS part depends upon how you have your Gemfile setup. You'll need that if you have a section sort of like this:

group :assets do
  gem 'jquery-rails'
  gem 'sass-rails'
  .... etc
end
笙痞 2024-12-19 01:24:54

development.rb 的正确设置是:

config.assets.debug = true; 
config.assets.compile = true;

您应该删除压缩行,因为这是一个相当耗时的过程,并且可能是速度缓慢的原因。

我建议查看 资产管道 Rails 指南,因为它具有升级应用程序配置的正确设置文件,以及一些有关部署的提示。

如果您不需要对文件进行任何调试,您也可以删除调试;这将只提供一个文件而不是许多文件。

The correct settings for development.rb are:

config.assets.debug = true; 
config.assets.compile = true;

You should remove the compress line, as this is quite an expensive process time-wise and may be the reason it is slow.

I would suggest looking at the asset pipeline Rails guide as this has the correct settings for an upgraded app's config files, and some tips about deploying too.

If you don't need to do any debugging on the files you could also remove debug; this will serve just one files instead of many.

左耳近心 2024-12-19 01:24:54

看看 https://github.com/wavii/rails-dev-tweaks

Rails 在开发模式下对每个 Sprockets 资源请求运行所有 to_prepare 挂钩。这包括自动(重新)加载代码之类的事情,以及各种宝石也潜入其中工作。 (Active Admin 就是其中之一)

rails-dev-tweaks 禁用 to_prepare 和根据任何资产请求重新加载(以及其他一些 - 阅读其自述文件的第一部分)。对于任何规模适当的项目,都可以极大地加快您的开发环境。还可以配置为您喜欢的任何其他请求执行此操作

Take a look at https://github.com/wavii/rails-dev-tweaks.

Rails is running all of the to_prepare hooks on every Sprockets asset request in development mode. This includes things like auto-(re)loading your code, and various gems sneak work in there too. (Active Admin is one of these gems)

rails-dev-tweaks disables to_prepare & reloading on any asset request (and a few others - read the first part of its README). Speeds up your dev environment by a huge amount for any decently sized project. It's also configurable to do this for any additional requests you like

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