Skip to content

Commit 75b4422

Browse files
committed
Refactor ad loading logic and update background images
- Updated nitroPay script to defer ad loading until after the page load completes for improved performance. - Changed background images from 'street2christmas.jpg' to 'street2.webp' across multiple components for better optimization.
1 parent 6ba0d95 commit 75b4422

File tree

9 files changed

+35
-21
lines changed

9 files changed

+35
-21
lines changed

components/headContent.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function HeadContent({ text, inCoolMathGames, inCrazyGames = fals
1515
// document.body.appendChild(scriptAp);
1616
// end adinplay script
1717

18-
// start nitroPay script - defer to after page is interactive
18+
// start nitroPay script - defer to after page load completes
1919
window.nitroAds=window.nitroAds||{createAd:function(){return new Promise(e=>{window.nitroAds.queue.push(["createAd",arguments,e])})},addUserToken:function(){window.nitroAds.queue.push(["addUserToken",arguments])},queue:[]};
2020

2121
const loadNitroAds = () => {
@@ -26,11 +26,19 @@ window.nitroAds=window.nitroAds||{createAd:function(){return new Promise(e=>{win
2626
document.head.appendChild(script);
2727
};
2828

29-
// Defer ad loading until after critical content
30-
if ('requestIdleCallback' in window) {
31-
requestIdleCallback(loadNitroAds, { timeout: 2000 });
29+
// Wait for page load event (ensures fonts/LCP complete), then defer further
30+
const scheduleAdLoad = () => {
31+
if ('requestIdleCallback' in window) {
32+
requestIdleCallback(loadNitroAds, { timeout: 3000 });
33+
} else {
34+
setTimeout(loadNitroAds, 1000);
35+
}
36+
};
37+
38+
if (document.readyState === 'complete') {
39+
scheduleAdLoad();
3240
} else {
33-
setTimeout(loadNitroAds, 1000);
41+
window.addEventListener('load', scheduleAdLoad, { once: true });
3442
}
3543

3644
// end nitroPay script

components/home.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useEffect, useState, useRef } from "react";
88
import Navbar from "@/components/ui/navbar";
99
import GameUI from "@/components/gameUI";
1010
import BannerText from "@/components/bannerText";
11-
import findLatLongRandom from "@/components/findLatLong";
11+
// findLatLongRandom is dynamically imported when needed to avoid loading Google Maps API on page load
1212
import Link from "next/link";
1313
import MultiplayerHome from "@/components/multiplayerHome";
1414
import AccountModal from "@/components/accountModal";
@@ -2091,12 +2091,18 @@ export default function Home({ }) {
20912091
options = options.sort(() => Math.random() - 0.5)
20922092
setOtherOptions(options)
20932093
} else {
2094-
function defaultMethod() {
2095-
console.log("[PERF] loadLocation: Calling findLatLongRandom");
2094+
async function defaultMethod() {
2095+
console.log("[PERF] loadLocation: Calling findLatLongRandom (dynamic import)");
20962096
const startTime = performance.now();
2097-
findLatLongRandom(gameOptions).then((latLong) => {
2097+
try {
2098+
const { default: findLatLongRandom } = await import("@/components/findLatLong");
2099+
console.log(`[PERF] findLatLong module loaded in ${(performance.now() - startTime).toFixed(2)}ms`);
2100+
const latLong = await findLatLongRandom(gameOptions);
20982101
setLatLong(latLong);
2099-
});
2102+
} catch (err) {
2103+
console.error("[ERROR] Failed to load location:", err);
2104+
toast(text("errorLoadingMap"), { type: 'error' });
2105+
}
21002106
}
21012107
function fetchMethod() {
21022108
//gameOptions.countryMap && gameOptions.offical
@@ -2166,7 +2172,7 @@ export default function Home({ }) {
21662172
}
21672173
defaultMethod()
21682174
}
2169-
}).catch((e) => {
2175+
}).catch(() => {
21702176
toast(text("errorLoadingMap"), { type: 'error' })
21712177
defaultMethod()
21722178
});
@@ -2373,7 +2379,7 @@ export default function Home({ }) {
23732379
msUserSelect: 'none',
23742380
pointerEvents: 'none',
23752381
}}>
2376-
<NextImage.default src={'./street2christmas.jpg'}
2382+
<NextImage.default src={'./street2.webp'}
23772383
draggable={false}
23782384
width={1920}
23792385
height={1080}
@@ -2422,7 +2428,7 @@ export default function Home({ }) {
24222428

24232429
{/* Loading overlay - covers iframe with background image to prevent white flicker */}
24242430
<div className={`loading-overlay ${loading ? 'loading-overlay--visible' : ''}`}>
2425-
<NextImage.default src={'./street2christmas.jpg'}
2431+
<NextImage.default src={'./street2.webp'}
24262432
draggable={false}
24272433
width={1920}
24282434
height={1080}

components/maps/mapsModal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default function MapsModal({ gameOptions, mapModalClosing, setGameOptions
117117
const styles = {
118118
// Full-viewport modal wrapper - fixed container, no scrolling
119119
modalShell: {
120-
background: `linear-gradient(0deg, rgba(0, 0, 0, 0.8) 0%, rgba(0, 30, 15, 0.6) 100%), url("/street2christmas.jpg")`,
120+
background: `linear-gradient(0deg, rgba(0, 0, 0, 0.8) 0%, rgba(0, 30, 15, 0.6) 100%), url("/street2.webp")`,
121121
backgroundSize: "cover",
122122
backgroundPosition: "center",
123123
boxShadow: "none",

components/settingsModal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function SettingsModal({ shown, onClose, options, setOptions, inC
3131
maxWidth: '500px',
3232
textAlign: 'center',
3333
position: "absolute",
34-
background: `linear-gradient(0deg, rgba(0, 0, 0, 0.8) 0%, rgba(0, 30, 15, 0.5) 100%), url("/street2christmas.jpg")`,
34+
background: `linear-gradient(0deg, rgba(0, 0, 0, 0.8) 0%, rgba(0, 30, 15, 0.5) 100%), url("/street2.webp")`,
3535
objectFit: "cover",
3636
backgroundSize: "cover",
3737
backgroundPosition: "center",

pages/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export default function UserProfilePage() {
242242
rgba(20, 26, 57, 0.8) 50%,
243243
rgba(0, 0, 0, 0.9) 100%
244244
),
245-
url("/street2christmas.jpg");
245+
url("/street2.webp");
246246
background-size: cover;
247247
background-position: center;
248248
background-attachment: fixed;

public/street2.webp

204 KB
Loading

styles/Leaderboard.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
rgba(20, 26, 57, 0.8) 50%,
99
rgba(0, 0, 0, 0.9) 100%
1010
),
11-
url("/street2christmas.jpg");
11+
url("/street2.webp");
1212
background-size: cover;
1313
background-position: center;
1414
background-attachment: fixed;

styles/MapPage.module.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
rgba(0, 30, 15, 0.8) 50%,
99
rgba(0, 0, 0, 0.9) 100%
1010
),
11-
url("/street2christmas.jpg");
11+
url("/street2.webp");
1212
background-size: cover;
1313
background-position: center;
1414
background-attachment: fixed;
@@ -481,7 +481,7 @@
481481
rgba(0, 20, 10, 0.9) 50%,
482482
rgba(0, 0, 0, 0.95) 100%
483483
),
484-
url("/street2christmas.jpg");
484+
url("/street2.webp");
485485
}
486486
}
487487

styles/accountModal.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
rgba(0, 30, 15, 0.8) 50%,
2727
rgba(0, 0, 0, 0.9) 100%
2828
),
29-
url("/street2christmas.jpg");
29+
url("/street2.webp");
3030
background-size: cover;
3131
background-position: center;
3232
/* Changed from background-attachment: fixed to position: fixed */
@@ -349,7 +349,7 @@
349349
rgba(0, 20, 10, 0.9) 50%,
350350
rgba(0, 0, 0, 0.95) 100%
351351
),
352-
url("/street2christmas.jpg");
352+
url("/street2.webp");
353353
background-size: cover;
354354
background-position: center;
355355
}

0 commit comments

Comments
 (0)