Skip to content

Commit

Permalink
Moved script tags from _app to _document
Browse files Browse the repository at this point in the history
  • Loading branch information
maxpetretta committed Sep 16, 2022
1 parent c9321ca commit 1e06fea
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 54 deletions.
51 changes: 0 additions & 51 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,13 @@
import { ThemeProvider } from "next-themes"
import type { AppProps } from "next/app"
import Head from "next/head"
import Script from "next/script"
import "../styles/globals.css"

export default function App({ Component, pageProps }: AppProps) {
return (
<>
<Head>
{/* Favicons */}
<link
rel="apple-touch-icon"
sizes="180x180"
href="/favicons/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/favicons/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/favicons/favicon-16x16.png"
/>
<link rel="manifest" href="/favicons/site.webmanifest" />
<link
rel="mask-icon"
href="/favicons/safari-pinned-tab.svg"
color="#4361a2"
/>
<meta name="msapplication-TileColor" content="#c73156" />
<meta name="theme-color" content="#111827" />
{/* Preconnects */}
<link rel="preconnect" href="https://vitals.vercel-insights.com" />
<link rel="preconnect" href="https://www.googletagmanager.com" />
<link rel="preconnect" href="https://www.google-analytics.com" />
</Head>
<ThemeProvider attribute="class" defaultTheme="light">
<Component {...pageProps} />
</ThemeProvider>
<Script src="/scripts/fade-in.ts" strategy="beforeInteractive" />
<Script src="/scripts/update-selector.ts" />
<Script src="/scripts/smoothscroll.min.js" />
<Script src="/scripts/smoothscroll-anchor.min.js" />
<Script
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}`}
/>
<Script id="gtag">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}', {
page_path: window.location.pathname,
});
`}
</Script>
</>
)
}
57 changes: 55 additions & 2 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Document, { Html, Head, Main, NextScript } from "next/document"
import Document, { Head, Html, Main, NextScript } from "next/document"
import Script from "next/script"

class MyDocument extends Document {
static async getInitialProps(ctx) {
Expand All @@ -9,10 +10,62 @@ class MyDocument extends Document {
render() {
return (
<Html lang="en">
<Head />
<Head>
{/* Favicons */}
<link
rel="apple-touch-icon"
sizes="180x180"
href="/favicons/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/favicons/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/favicons/favicon-16x16.png"
/>
<link rel="manifest" href="/favicons/site.webmanifest" />
<link
rel="mask-icon"
href="/favicons/safari-pinned-tab.svg"
color="#4361a2"
/>
<meta name="msapplication-TileColor" content="#c73156" />
<meta name="theme-color" content="#111827" />
{/* Preconnects */}
<link rel="preconnect" href="https://vitals.vercel-insights.com" />
<link rel="preconnect" href="https://www.googletagmanager.com" />
<link rel="preconnect" href="https://www.google-analytics.com" />
</Head>
<body>
<Main />
<NextScript />
<Script
src="/scripts/fade-in.js"
type="module"
strategy="beforeInteractive"
/>
<Script src="/scripts/update-selector.js" />
<Script src="/scripts/smoothscroll.min.js" />
<Script src="/scripts/smoothscroll-anchor.min.js" />
<Script
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}`}
/>
<Script id="gtag">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}', {
page_path: window.location.pathname,
});
`}
</Script>
</body>
</Html>
)
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion tsconfig.tsbuildinfo

This file was deleted.

0 comments on commit 1e06fea

Please sign in to comment.