What does PrefetchPlugin do?

It says:

A request for a normal module, which is resolved and built even before a require to it occurs. This can boost performance.

I don’t see how it can boost performance.
Why is a nested require() much slower than the same root level require()?

Author: Fantashit

5 thoughts on “What does PrefetchPlugin do?

  1. The plugin is for prefetching assets over the wire before the require is executed. For example prefetching code to render a different view in a single-page app. So while a user is looking at the current page the code for another page that is not in the original page payload is downloaded before the user attempts to navigate to that page.

  2. @aackerman oh, that makes sense. But how does it boost Webpack build performance? (as per Analyse Tool hints)

    Long module build chains
    Use prefetching to increase build performance. Prefetch a module from the middle of the chain.
  3. long chains of requires can form a chain where webpack will know about the last module very late. This could slow down the compilation because webpack has to wait for I/O (esp. resolving). The PrefetchPlugin starts modules earlier so I/O is less an concern.

Comments are closed.