防止在非 active_admin 页面上加载活动管理资源

prevent active admin resources from loading on non active_admin pages

我正在使用 active_admin,效果很好。活跃的管理员有很多依赖关系,比如 jquery-ui, datepicker etc..

<script src="/assets/active_admin/jquery_ui.self-75a11da44c802486bc6f65640aa48a730f0f684c5c07a42ba3cd1735eb3fb070.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/active_admin/base.self-ab2cb3098b53fe7d229937d768d701e8f4013f2a5aea7988d8f2149fa40426db.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/active_admin/lib/batch_actions.self-fbed82dc1e31cf860056cce6c02f5bc5831ad5343d68ac3ab17471c9e05e9195.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/active_admin/lib/checkbox-toggler.self-ab6f686db7db58fd7f370cd6f7a6d7abe6884b8d2a144f42a744c2276587b457.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/active_admin/lib/dropdown-menu.self-8ccb356121a1c40094bb429d6cfac85d9c8ad114fb93730892d9df9986730a0a.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/active_admin/lib/flash.self-8f05a5d9328ea28fca100b057787fbfb567986513c5f1735ea48fad8f9571c10.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/active_admin/lib/has_many.self-ece319debdc01ca5096ae8ac6c130ffc0decab382543b4b94e18591375d3d3bb.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/active_admin/lib/modal_dialog.self-5dfc6e87bae26cd4a021eb86951d3691ed07e6d2bf242a8eb65dc6965e12096c.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/active_admin/lib/per_page.self-94323c49402595a22bdea01b8dc3f8103e290d300238ebd49efa26d76d7ee117.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/active_admin/lib/table-checkbox-toggler.self-f5200d732ec9ffd4ee8fd1fe11524ad7b54a67f6c0ef447a29d119ece2dcecdb.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/active_admin/ext/jquery-ui.self-f96f2ec2a32c4bc4da4292cc74bddeca0bb223d81a421c98c4d613632860945e.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/active_admin/ext/jquery.self-da8dafbbe883092bcae73f35a8caf4ae6170fe7d8130ae7039a233f9b509c757.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/active_admin/initializers/batch_actions.self-f5c360e8640b40f00640f6e5c7cfe0addeb244ed72e1a9828c52919515d23cf1.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/active_admin/initializers/datepicker.self-f8ac66c85afd35ee1555c09a2418efc7a7930e1f6dd783461379c2bb2184f80e.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/active_admin/initializers/filters.self-9b9312d6bed532db668c5417a009b7fb7caf58f33299783ed02c2c72340a498a.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/active_admin/initializers/tabs.self-65de8b1688d4f8782c04bf07ba6314d3c8b33b9391a482a07214ac4df99dd904.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/active_admin.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1" data-turbolinks-track="reload"></script>

我没有在我的应用程序的任何其他部分使用这些。但我可以看到,无论管理页面是否处于活动状态,它都会加载。那么是否可以只为活动的管理页面加载这些资源? (如果不可能,是否可以从 asset pipeline 中删除活动管理员,以便不会在 other app parts 中加载依赖项)?

你能删除吗 //= require_tree . 来自你的 application.js 然后再试一次?

类似于 Fivell 的回答。我在 required_tree . 之后通过 stub 修复了它,以避免 application.js 中需要 active_admin.js

所以app/assets/javascripts/application.js会变成这样:

// This is a manifest file that'll ...
// ...
//= require rails-ujs
//= require activestorage
//= require_tree .
//= stub active_admin

在我的例子中(Rails 5.2.3 和 ActiveAdmin 2.1.0),改变这个不会阻止 ActiveAdmin 加载 active_admin.css & active_admin.js 所以管理页面应该是很好。