question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introduce code-splitting to web app

See original GitHub issue

Right now, running npm run build in the server/ project generates one main.min.js bundle weighing in at 1.43 MB.

Version: webpack 3.12.0
Time: 14165ms
       Asset     Size  Chunks                    Chunk Names
 main.min.js  1.43 MB       0  [emitted]  [big]  main
main.min.css   133 kB       0  [emitted]         main

If some code-splitting refactors are introduced, that could reduce the overall bundle size (a potential performance improvement). Some thoughts on how this could be introduced / places to look at code-splitting:

The first step would be adding support for the dynamic import() function to Babel using @babel/plugin-syntax-dynamic-import for supporting dynamic imports being compiled by Webpack + Babel (my understanding is that Webpack uses import() statements as code split points).

I’ve found react-loadable a helpful library for defining code split points for React components, as you can change the way you import the component but continue to render it the same way and benefit from code splitting.

// ListItem.js

// instead of this
import ReactJson from 'react-json-view'

// lazy load instead
import Loadable from 'react-loadable'
const ReactJson = Loadable({
  loader: () => import('react-json-view'),
  loading: LoadingComponent, // TODO
})

I think a good first component to code split out could either be <ListItem> or the default import from react-json-view, since that component is not visible until a user expands the list item to view payload data. bundlephobia reports that react-json-view is 36.1kB minified and gzipped, so reducing that size from the initial bundle would likely improve load/parse times.

Some other places where code-splitting could be worth investigating to see if there are potential bundle size wins:

  • Split the vendor libraries into their own chunk. This would contain 3rd party libraries and would be cached in the user’s browser unless they emptied their cache or smee shipped a new version of the vendor bundle (updated libraries), which could improve loading time.
  • Explore lazy loading icons in the <EventIcon>'s icon map. I’m guessing the icons are pretty small, but maybe loading them only when they are needed or at some point after the initial bundle has been downloaded could be a minor performance improvement?

https://github.com/probot/smee/blob/79cfefe731d23b68abed09ca7d67daa37897f628/server/src/components/EventIcon.js#L24-L46

One open question would be around react-loadable’s loading component and what that would look like in the context of where different app components are being loaded dynamically, but I’m probably getting ahead of myself of that one. 😅

Would you be interested in pull requests to help with this enhancement? Any thoughts around this?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
macklinucommented, Dec 14, 2018

Most definitely, no offense, just looking to engage in open source projects that I use / enjoy and see what I can help with from both practical and nice-to-have standpoints. ❤️

0reactions
macklinucommented, Dec 16, 2018

I think a lot of the underlying problems of this have been addressed in #86, and if there are further improvements to lowering bundle size, let’s open them up in separate issues. Closing this one. ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code-Splitting - React
Code -Splitting is a feature supported by bundlers like Webpack, Rollup and ... The best way to introduce code-splitting into your app is...
Read more >
Introducing Code Splitting to a React Web App
Code -splitting your app can help you “lazy-load” just the things that are currently needed by the user, which can dramatically improve the...
Read more >
Speed Up Your React Apps With Code Splitting - YouTube
Introduction. •. Scroll for details. #React #WDS. Speed Up Your React Apps With Code Splitting. 136K views 2 weeks ago. Web Dev Simplified....
Read more >
A Gentle Introduction to Code Splitting with React - kommit
This is the most popular way when it comes to code splitting our app. Assuming you have some experience with any kind of...
Read more >
Code Splitting in React Native Applications | blog {callstack}
Code splitting is a technique to produce multiple output files which, as a whole, contains all your application's functionality, but allows them ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found