Code Splitting with React and React Router

Code Splitting with React and React Router  #reactjs #React #reactrouter

  • Code splitting has gained popularity recently for its ability to allow you to split your app into separate bundles your users can progressively load.
  • In this post we’ll take a look at not only what code splitting is and how to do it, but also how to implement it with React Router.
  • You already split your app into different routes, so adding in code splitting on top of that feels pretty natural.
  • Instead of thinking about code splitting as splitting your app up by its routes, you should think of it as splitting your app up by its components ( s are just components, after all).
  • You already know how to dynamically import modules with , now you just need to figure out which components in your app you can hold off downloading until your user needs them.

Code splitting has gained popularity recently for its ability to allow you to split your app into separate bundles your users can progressively load. In this post we’ll take a look at not only what code splitting is and how to do it, but also how to implement it with React Router.

Code splitting has gained popularity recently for its ability to allow you to split your app into separate bundles your users can progressively load. In this post we’ll take a look at not only what code splitting is and how to do it, but also how to implement it with React Router.

It’s 2018. Your users shouldn’t have to download your entire app when all they need is a piece of it. If a user is creating a new post, it doesn’t make sense to have them download all the code for the Registration view. If a user is registering, they don’t need the huge rich text editor your app needs on the Settings view. It’s wasteful and some would argue disrespectful to those users who don’t have the privilege of unlimited bandwidth. This idea has not only gained much more popularity in recent years, but it’s also become exponentially easier to pull off – it even has a fancy cool name – code splitting.

The idea is simple, don’t download code until the user needs it. In practice, it can be a little more complicated. The reason for this isn’t because code splitting itself is terribly difficult, but that there are various tools to do it and everyone has an opinion on which is the best. When you’re first starting out, it can be hard to parse what is what.

If you’re familiar with…

Code Splitting with React and React Router