【发布时间】:2019-11-18 21:26:59
【问题描述】:
我正在运行rails assets:precompile,它会输出:
WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
This can impact web performance.
Assets:
js/application-c4e0541a90e01b47fbfe.js (1.21 MiB)
js/chartkick-b109b176a3de896848c7.js (657 KiB)
js/datatables-fca8769ee16df57bdc4a.js (296 KiB)
js/application-c4e0541a90e01b47fbfe.js.gz (305 KiB)
js/datatables-fca8769ee16df57bdc4a.js.map.gz (482 KiB)
js/chartkick-b109b176a3de896848c7.js.map.gz (493 KiB)
js/application-c4e0541a90e01b47fbfe.js.map.gz (1.09 MiB)
WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
Entrypoints:
application (1.21 MiB)
js/application-c4e0541a90e01b47fbfe.js
chartkick (657 KiB)
js/chartkick-b109b176a3de896848c7.js
datatables (296 KiB)
js/datatables-fca8769ee16df57bdc4a.js
WARNING in webpack performance recommendations:
You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.
For more info visit https://webpack.js.org/guides/code-splitting/
我一直在研究延迟加载,但找不到任何关于 Rails 的信息(我对 webpacker、js 等非常陌生)。 例如,link 解释了拆分代码和延迟加载,但我不知道如何在我的超级简单代码上调用它。
这是我拥有的数据表代码示例:
//Global setting and initializer
// Add DataTables jQuery plugin
require('imports-loader?define=>false!datatables.net')(window, $)
require('imports-loader?define=>false!datatables.net-select')(window, $)
require('imports-loader?define=>false!datatables.net-bs4')(window, $)
require('imports-loader?define=>false!datatables.net-select-bs4')(window, $)
// Load datatables styles
import 'datatables.net-bs4/css/dataTables.bootstrap4.css'
import 'datatables.net-select-bs4/css/select.bootstrap4.css'
$(document).on('turbolinks:load', () => {
$(document.body).on('click', '#check_all', () => {
var checkBoxes = $('input[type="checkbox"]')
checkBoxes.prop("checked", !checkBoxes.prop("checked"))
})
})
// init on turbolinks load
$(document).on('turbolinks:load', function() {
if (!$.fn.DataTable.isDataTable(".datatable")) {
$(".datatable").DataTable();
}
});
// turbolinks cache fix
$(document).on('turbolinks:before-cache', function() {
var dataTable = $($.fn.dataTable.tables(true)).DataTable();
if (dataTable !== null) {
dataTable.destroy();
return dataTable = null;
}
});
很想得到一些指示,它阻塞了我的应用程序并且应用程序崩溃了。 谢谢!
【问题讨论】:
标签: jquery ruby-on-rails webpack webpacker ruby-on-rails-6