Skip to content

Commit 567bd93

Browse files
committed
Refactor Naver WCS script integration by moving it to _document.tsx for improved loading strategy and event handling
1 parent cf26afd commit 567bd93

2 files changed

Lines changed: 20 additions & 22 deletions

File tree

src/pages/_app.tsx

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
import { Analytics } from "@vercel/analytics/react";
1818
import { SpeedInsights } from "@vercel/speed-insights/next";
1919
import { OverlayProvider } from "overlay-kit";
20-
import Script from "next/script";
2120

2221
const qc = new QueryClient();
2322

@@ -50,27 +49,6 @@ export default function App({ Component, pageProps }: AppProps) {
5049
</QueryClientProvider>
5150
<Analytics />
5251
<SpeedInsights />
53-
54-
{/* Naver WCS common script */}
55-
<Script src="//wcs.naver.net/wcslog.js" />
56-
<Script
57-
type="text/javascript"
58-
id="naver-wcs-script"
59-
dangerouslySetInnerHTML={{
60-
__html: `
61-
document.addEventListener('DOMContentLoaded', function() {
62-
var _nasa={}; //초기화구문
63-
if (!window.wcs_add.wa) window.wcs_add = { wa: "s_5a3318c599a1"};
64-
if (!_nasa) var _nasa={};
65-
if(window.wcs){
66-
wcs.inflow("xn--hn2bp0nf8g.com");
67-
wcs_do(_nasa);
68-
var _nasa={}; //초기화구문
69-
}
70-
});
71-
`,
72-
}}
73-
/>
7452
</>
7553
);
7654
}

src/pages/_document.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Head, Html, Main, NextScript } from "next/document";
2+
import Script from "next/script";
23

34
export default function Document() {
45
return (
@@ -31,6 +32,25 @@ export default function Document() {
3132
<link rel="manifest" href="/site.webmanifest" />
3233
<meta name="msapplication-TileColor" content="#ffffff" />
3334
<meta name="theme-color" content="#ffffff" />
35+
<Script
36+
src="//wcs.naver.net/wcslog.js"
37+
strategy="beforeInteractive"
38+
></Script>
39+
<Script strategy="lazyOnload" id="naver-wcs-script">
40+
{`
41+
document.addEventListener('DOMContentLoaded', function() {
42+
var _nasa={}; //초기화구문
43+
if (!window.wcs_add.wa) window.wcs_add = { wa: "s_5a3318c599a1"};
44+
if (!_nasa) var _nasa={};
45+
if(window.wcs){
46+
wcs.inflow("xn--hn2bp0nf8g.com");
47+
wcs_do(_nasa);
48+
var _nasa={}; //초기화구문
49+
}
50+
});
51+
}
52+
`}
53+
</Script>
3454
</Head>
3555
<body className="antialiased">
3656
<Main />

0 commit comments

Comments
 (0)