NOTE: This answer is due to confusion. The OP is not using React but the report includes the React example. This might be helpful to others
anyways.
If your components are loaded dynamically ( only after a user request for it ).
You can use React.lazy()
as suggested in the report for code splitting so that you don't load the large bundle when not necessary.
This solution is for non SSR.
BEFORE:
import ComponentB from './ComponentB';
function ComponentA() {
return (
<>
{/* After certain action probably like routes switch or any? */}
<ComponentB />
</>
);
}
AFTER:
import React, { lazy } from 'react';
const ComponentB = lazy(() => import("./ComponentB.js"));
function ComponentA() {
return (
<>
{/* After certain action probably like routes switch or any? */}
<ComponentB />
</>
);
}
Reference: https://reactjs.org/docs/code-splitting.html