bundle-loader icon indicating copy to clipboard operation
bundle-loader copied to clipboard

Advantages/disadvantages over import()

Open iamakulov opened this issue 8 years ago • 1 comments

I’d like to document how this solution is different from import()/require.ensure(). This would simplify the choice between these tools: from the first sight, bundle-loader?lazy and import() are very similar, and you could get stuck thinking what to choose.

This is what I’ve found so far:

  • Advantage: Per react-router docs, on additional renders, the loader calls the callback synchronously. This prevent the flashing of the loading screen.
  • Disadvantage: import() and require.ensure() allow handling the loading error (e.g. with .catch()), and bundle-loader doesn’t.
  • Disadvantage: Because this is a loader, the developer should either
    • name a file after a specific pattern (e.g. .lazy.js) to apply the loader to it (this requires renaming files, which is a pretty large event) or
    • specify the loader inline (which is a rare and webpack-specific notation).

Are there any other known differences I’m missing?

iamakulov avatar Nov 30 '17 21:11 iamakulov

Thanks @iamakulov for writing this up. I thought this exists because import() wasn't a thing. would like to see the opinions from the maintainers.

stevemao avatar Nov 05 '18 03:11 stevemao