Skip to content

Commit

Permalink
Use next/script to help load 3P scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
timngyn committed Dec 7, 2023
1 parent 390d61e commit 2bbc329
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
27 changes: 19 additions & 8 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@aws-amplify/ui-react/styles.css';
import '../styles/styles.scss';
import Head from 'next/head';
import Script from 'next/script';
import { MDXProvider } from '@mdx-js/react';
import { Layout } from '@/components/Layout';
import { CANONICAL_URLS } from '@/data/canonical-urls';
Expand Down Expand Up @@ -178,23 +179,33 @@ function MyApp({ Component, pageProps }) {

<MDXProvider>{getLayout(<Component {...pageProps} />)}</MDXProvider>

<Script
src="https://prod.assets.shortbread.aws.dev/shortbread.js"
strategy="afterInteractive"
></Script>
{process.env.BUILD_ENV !== 'production' ? (
<>
{/* eslint-disable-next-line @next/next/no-sync-scripts */}
<script src="https://aa0.awsstatic.com/s_code/js/3.0/awshome_s_code.js"></script>
<script
<Script
src="https://aa0.awsstatic.com/s_code/js/3.0/awshome_s_code.js"
strategy="beforeInteractive"
></Script>
<Script
src="https://alpha.d2c.marketing.aws.dev/client/loader/v1/d2c-load.js"
defer
></script>
strategy="afterInteractive"
></Script>
</>
) : (
<>
{/* eslint-disable-next-line @next/next/no-sync-scripts */}
<script src="https://a0.awsstatic.com/s_code/js/3.0/awshome_s_code.js"></script>
<script
<Script
src="https://a0.awsstatic.com/s_code/js/3.0/awshome_s_code.js"
strategy="beforeInteractive"
></Script>
<Script
src="https://d2c.aws.amazon.com/client/loader/v1/d2c-load.js"
defer
></script>
strategy="afterInteractive"
></Script>
</>
)}
<link
Expand Down
4 changes: 0 additions & 4 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ export default class MyDocument extends Document {
httpEquiv="Content-Security-Policy"
content={getCspContent(this.props)}
/>
<script
src="https://prod.assets.shortbread.aws.dev/shortbread.js"
defer
></script>
</Head>
<body>
<Main />
Expand Down

0 comments on commit 2bbc329

Please sign in to comment.