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

99
Views
Lazy load large SVG component in React

I'm working on a Gatsby project that has a large (about 300kb) SVG component. Is there a way to lazy load this component, ideally displaying a loading spinner? I would like to prevent the large SVG from negatively impacting the first paint. Some elements of this component have event listeners and click events to route the user to different pages, so it's not just a static SVG image.

import React from "react";
import { navigate } from "gatsby";

const clickEventHandler = () => {
    // some logic
    // ...
    navigate("/path")
};

export default function SVGMap() {
//... some component logic ...

    return (
        <svg id='very-large-svg'>
            <path d="" style={{...}} onClick={clickEventHandler} />
        </svg>
)};

In my landing page I would like to use this element

import SVGMap from './svgmap.js'

export default function Page() {
    return(
    <>
        {/* Lazy load this while the rest of the page is already being displayed */}
        <SVGMap /> 
    </>
    )
};

Is there any way how to do this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use React.lazy with suspense for code-splitting.

const SVGMap = React.lazy(() => import('./svgmap'));

<Suspense fallback={""}>
  <SVGMap />
</Suspense>

https://tr.reactjs.org/docs/code-splitting.html#reactlazy

or you can use @loadable/component 3th party libary.

import loadable from '@loadable/component'
const SVGMap = loadable(() => import('./svgmap'))

https://loadable-components.com/docs/getting-started/

about 4 years ago · Juan Pablo Isaza 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!