0

According to Webpack there's a property on the output object in their configuration settings. https://webpack.js.org/configuration/output/#outputasyncchunks

I am struggling to understand what exactly this will do and when/why it should be set to a certain value (true/false).

I can't seem to find any explanations online either, other than another SO post linking to another article which is about a different property (see: What is an async chunk in webpack?).

So is there anyone that can help me out and explain to me in simple terms when and why to use asyncChunks and what it will do?

5
  • 1
    It just means the chunks are loaded asynchronously so it doesn’t block your UI. It defaults to true. You probably should not set it to false unless you know what you’re doing. Commented Jan 9, 2024 at 23:33
  • @Terry I'm afraid I'm still a bit confused. Doesn't Webpack compile everything meaning as soon as it's served it's already loaded the bundled chunk including all the dependencies? What's the need for asynchronous loading in that case? Commented Jan 9, 2024 at 23:39
  • That’s the thing. You don’t want to load a single, monolithic chunk. Webpack will tend to bundle codes into chunks depending on how they’re consumed. In an app with multiple pages for example, code that is shared by multiple pages will be in one (or a few) bundle so that the browser only needs to load it once. Commented Jan 9, 2024 at 23:51
  • @Terry Are those chunks grouped by entry points defined in the configuration file? Meaning if I have multiple entry points (an app with multiple pages as you stated), they will load asynchronously. If I have a single entry point however, the "output.asyncChunks" won't really change much, am I correct? Commented Jan 10, 2024 at 16:06
  • That is incorrect. Chunks are not grouped by entry points, but they may be influenced by them. You can have multiple entry points sharing a common function, in that case it is highly likely the chunk where this function is in will be loaded across various entry points. Commented Jan 11, 2024 at 19:55

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.