Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
Single import from an index file vs multiple single imports - Effects on Performance?

Background

I'm using Gatsby to build a blog, and I'm trying to improve performance. I also want to implement code-splitting and lazy loading.

2 Ways of importing components

Let's say I have to import 2 components that are in the same folder; there are two ways to do this:

Way 1: Group all the components in an index.ts file

import { Component1, Component2 } from '../components/index.ts'

Way 2: Import the single components referencing the specific path

import { Component1 } from '../components/Component1'
import { Component2 } from '../components/Component2'

Question

The first way looks better and is faster to code, but what are its effects on performance?

From what I read in the Gatsby Documentation, the second approach should be preferred, because otherwise Webpack will bundle and import also other components that you don't actually need, thus increasing the size of the bundle (and negatively effecting performance).

Should I then convert all my grouped imports into specific imports, and remove the index.ts files?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

If you use an up-to-date webpack version, then the tree shaking feature will minimize what is imported into the generated bundle for either way you described.

In the link you gave, it is specifically referring to Gatsby v2, so I'm assuming that it no longer holds for v3 and up.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!