Skip to content

Commit

Permalink
Move beforeInteractive script to _document
Browse files Browse the repository at this point in the history
  • Loading branch information
timngyn committed Dec 7, 2023
1 parent 2bbc329 commit 1913827
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
10 changes: 0 additions & 10 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,13 @@ function MyApp({ Component, pageProps }) {
></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"
strategy="beforeInteractive"
></Script>
<Script
src="https://alpha.d2c.marketing.aws.dev/client/loader/v1/d2c-load.js"
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"
strategy="beforeInteractive"
></Script>
<Script
src="https://d2c.aws.amazon.com/client/loader/v1/d2c-load.js"
strategy="afterInteractive"
Expand Down
18 changes: 18 additions & 0 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import crypto from 'crypto';
import Document, { Html, Head, Main, NextScript } from 'next/document';
import Script from 'next/script';

const cspHashOf = (text) => {
const hash = crypto.createHash('sha256');
Expand Down Expand Up @@ -118,6 +119,23 @@ export default class MyDocument extends Document {
<body>
<Main />
<NextScript />
{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"
strategy="beforeInteractive"
></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"
strategy="beforeInteractive"
></Script>
</>
)}
</body>
</Html>
);
Expand Down

0 comments on commit 1913827

Please sign in to comment.