Update
I visited the website and I'm sure you are using Gatsby. Gatsby is using SSR and React.lazy and Suspense are not yet available for server-side rendering. If you want to do code-splitting in a server-rendered app, Loadable Components is recommended in React docs. It has a nice guide for bundle splitting with server-side rendering.
There is a gatsby plugin to make your life easier gatsby-plugin-loadable-components-ssr. After you install and configure the plugin you can use loadable
like this:
AmazonFrame.js
import React from "react";
const AmazonFrame = ({ src, width, height }) => (
<iframe src={src} width={width} height={height} scrolling="no"></iframe>
);
App.js
import React from "react";
import loadable from "@loadable/component";
const AmazonFrame = loadable(() => import("./AmazonFrame"), {
fallback: <div>Loading...</div>
});
function App() {
return (
<div>
<AmazonFrame src="src" width="100%" height="200px" />
</div>
);
}
export default App;
or
import React from "react";
import loadable from "@loadable/component";
const AmazonFrame = loadable(() => import("./AmazonFrame"));
function App() {
return (
<div>
<AmazonFrame fallback={<div>Loading...</div>} />
</div>
);
}
export default App;
Original answer
You need to use Code-Splitting. Code-Splitting is a feature supported by bundlers like Webpack, Rollup, and Browserify (via factor-bundle) which can create multiple bundles that can be dynamically loaded at runtime.
If you’re using Create React App, this is already configured for you and you can start using it immediately.
Code-splitting your app can help you “lazy-load” just the things that are currently needed by the user, which can dramatically improve the performance of your app. While you haven’t reduced the overall amount of code in your app, you’ve avoided loading code that the user may never need, and reduced the amount of code needed during the initial load.
Here is an example solution to your problem which will lazy load the Amazon ads iframe
so it won't be loaded with your initial bundle:
AmazonFrame.js
import React from "react";
const AmazonFrame = ({ src, width, height }) => (
<iframe src={src} width={width} height={height} scrolling="no"></iframe>
);
export default AmazonFrame;
App.js
import React, { Suspense, lazy } from "react";
// React.lazy takes a function that must call a dynamic import(). This must return a Promise
// which resolves to a module with a default export containing a React component.
const AmazonFrame = lazy(() => import("./AmazonFrame"));
function App() {
return (
<div>
{/* The lazy component should then be rendered inside a Suspense component, which allows us to show some fallback
content (such as a loading indicator) while we’re waiting for the lazy component to load */}
{/* The fallback prop accepts any React elements that you want to render while waiting for the component to load */}
<Suspense fallback={<div>Loading...</div>}>
<AmazonFrame src="src" width="100%" height="200px" />
</Suspense>
</div>
);
}
export default App;