How does Webpack's code splitting work

放肆的年华 提交于 2019-12-11 02:38:26

问题


I know little bit about webpack, but can not find a simple answer to my question. What does code splitting with Webpack mean?

Is it creating individual bundle js files for different routes and performing ajax operations for getting these js files when requested by the client.

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?

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.


回答1:


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.

The actual loading of bundled js is done by script tag injection.

When the actual loading should be done is handled by the router. If you are using react-router this is a quick example.

Hope this helps somewhat.



来源:https://stackoverflow.com/questions/36744027/how-does-webpacks-code-splitting-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!