问题描述
我对webpack知之甚少,但是找不到我的问题的简单答案。使用Webpack进行代码拆分意味着什么?
I know little bit about webpack, but can not find a simple answer to my question. What does code splitting with Webpack mean?
是否根据客户端的请求创建了单独的bundle js文件,并执行ajax操作来获取这些js文件。
Is it creating individual bundle js files for different routes and performing ajax operations for getting these js files when requested by the client.
还是在第一次点击后正确显示了第一个请求的页面后,执行异步调用以从服务器获取其他单独的js文件?
Or is it performing async calls for getting other individual js files from server after showing the first requested page properly after the first hit?
在我学习如何做之前,我想对自己所学的知识有所了解。 Webpack文档完全没有帮助。假定您完全了解webpack的工作原理。
Before I learn how to do, I would like to have an idea about what I am learning. Webpack docs doesn't help at all. It assumes you fully understand how webpack works.
推荐答案
代码拆分将您的应用拆分为多个捆绑的js。例如,如果您的应用程序有一个管理员部分,您的用户永远看不到,您可以将其分成2个捆绑包,这样用户就不会下载与管理员相关的js。
Code splitting splits up your app into multiple bundled js. For example if you had a admin section to your app which your users will never see you can split it up into 2 bundles, this way users will not download the admin related js.
捆绑的js的实际加载是通过脚本标记注入完成的。
The actual loading of bundled js is done by script tag injection.
何时应完成实际加载由路由器处理。如果您使用的是react-router,这是一个快速的。
When the actual loading should be done is handled by the router. If you are using react-router this is a quick example.
希望这会有所帮助。
这篇关于Webpack的代码拆分如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!