A click-to-play iframe is a game frame that does not exist until the visitor asks for it. The page shows a picture of the game and a Play button. Pressing the button creates the iframe. Until then the browser has downloaded nothing from the game host, neither the game nor its ad code. On an HTML5 game site this one decision does more for page speed than anything else you can change, and it is also the simplest way to keep a third party off the page until a visitor has chosen to let it in.
This post goes through the PuzzleMoss version of the component and the reasons behind each part. It is a closer look at step 5 of how to add GameMonetize games to your website, which covers the feed and filtering side.
Why loading="lazy" is not the answer
Most results for "lazy load iframe" recommend the native attribute: put loading="lazy" on the iframe and let the browser hold it back until it is near the viewport. That works well for a map at the bottom of a long article. It does very little for a game page, because the game frame sits at the top. It is in the viewport on arrival, so the browser loads it straight away, which is exactly what the attribute is meant to do.
Google's own guidance on embeds says the native attribute also behaves differently from browser to browser. Its article on third-party embed best practices notes that browsers decide when to load using the distance from the viewport together with signals such as the effective connection type, so the timing is not something you control. The same article puts many popular embeds at over 100 KB of JavaScript, and some at up to 2 MB.
The pattern that does fit is what Lighthouse calls a facade. The Lighthouse documentation on facades describes it as a static element that looks like the embed but does not work, with the real embed loaded only when the user interacts with it. Its worked example is a video player: a 3 KB facade on the page, and a 540 KB player loaded on click. A game iframe loads a whole game, engine and assets included, so it is not the lighter of the two.
What the visitor sees first
The facade on a PuzzleMoss game page is the game's thumbnail, dimmed, with a round Play button in the middle and a line underneath that says the game loads only when you press Play. That line is there so the empty frame is not mistaken for a broken one.
The thumbnail is the largest thing above the fold, so it is the image the browser will treat as the page's main content when it measures load speed. It is marked as a priority image and is not lazy loaded. Lazy loading the one image the visitor sees first would slow the page down, not speed it up.
Be honest with yourself about what the facade still fetches. PuzzleMoss hotlinks thumbnails from GameMonetize's image server and preconnects to that host. What it never contacts before the click is the host that serves the games. The two are separate domains, and the distinction matters for the next section.
Where Google's advice and consent disagree
The Lighthouse page suggests three steps: show the facade on load, preconnect to the third party's servers when the pointer moves over it, and swap in the real embed on click. The middle step is a sensible speed trick. On a site that takes consent seriously it is a problem, because a preconnect is a real connection. The browser opens it to the game host before the visitor has clicked anything, which hands that host the visitor's IP address as surely as loading the game would.
PuzzleMoss skips the hover preconnect and takes the slower start instead. The site's cookie banner offers Decline and Accept as buttons of the same size and weight, and stores the choice. The game component reads that choice when the visitor presses Play:
- If the visitor accepted optional cookies, Play loads the game.
- If they declined or have not chosen yet, Play opens a short notice inside the frame. It says the game is served by GameMonetize, which may set its own cookies, including for in-game ads, and offers "Not now" and "Load the game", styled identically.
"Not now" puts the frame back as it was. "Load the game" loads that one game and nothing else. Declining once does not lock anyone out of the site, and accepting on one game does not quietly change the site-wide choice. When the launch build was tested, a visitor who declined made no requests to the game host at all until they confirmed on a specific game.
The notice exists because the click alone is not informed consent. A visitor pressing Play wants to play; they have not been told that a different company is about to set cookies. One extra tap for those who declined is a small price, and visitors who accepted never see it.
Sizing: a 16:9 box with any game inside
The feed gives every game a width and a height, and they vary a lot. Of the 252 games in the PuzzleMoss catalogue today, 170 are wider than they are tall, 81 are portrait and 1 is square. A fixed 16:9 iframe stretches the portrait ones into something unplayable, and resizing the outer frame per game makes every page a different shape and pushes the text below it around as the page loads.
The fix is two boxes. The outer box is always 16:9 (CSS aspect-ratio reserves the space before anything loads, so nothing jumps). The iframe inside is sized from the game's own ratio:
- If the game is narrower than 16:9, the iframe takes the full height, and its width is the game's ratio divided by 16:9, as a percentage.
- If it is wider, it takes the full width, and its height is 16:9 divided by the game's ratio.
Bubble Sorting is 720 by 1280, a ratio of 0.5625. Divided by 1.778, that gives an iframe 31.6% of the box wide, centred, with dark bars either side. Fruit Box Sort at 750 by 1334 comes out almost the same. Crystal Cave Sort is 1920 by 1080, which is exactly 16:9, so it fills the frame. All three are in the sort and organise section which has plenty of portrait games.
Guard against bad data. If the feed gives a width or height of zero or something that is not a number, fall back to 16:9 rather than dividing by zero.
Fullscreen on the wrapper, not the game
Some games have their own fullscreen control and some do not. A button under the frame calls the Fullscreen API on the outer box, which works for every game, and the iframe's allow attribute lists fullscreen for the games that try it themselves. The button stays disabled until a game is loaded, since fullscreen on a thumbnail is pointless. Older Safari needs the prefixed webkitRequestFullscreen, so the component checks for both.
A pillarboxed portrait game stays pillarboxed in fullscreen, because the inner box keeps its percentages. That is the right result on a desktop monitor. On a phone held upright, the visitor would usually do better with the game alone, which is a fair argument for a dedicated mobile layout later.
Small things that are easy to miss
The Play control is a real button element with an accessible name that includes the game title ("Play Bubble Sorting"), so it works with a keyboard and a screen reader without extra code. The iframe has a title attribute for the same reason.
A loading state covers the gap between the click and the game's first frame. The component shows a spinner and the game's name, then removes them when the iframe fires its load event. Without it, a slow connection shows a black box for several seconds and people press Play again.
Nothing is rendered on the server. Because the iframe only exists after a click, the built HTML for a game page contains no iframe tag at all. That is easy to check: build the site and search the output folder for <iframe. On PuzzleMoss the search comes back empty, and a separate check, run before every deploy, fails if any page carries a third-party script, so a later change cannot slip one in.
Do not edit the embed URL. The feed's URL is used exactly as it comes. Adding parameters to strip the developer's ads or branding breaks GameMonetize's terms and takes away the developer's income.
Is it worth the work?
For a page with a single game at the top, yes. The PuzzleMoss component is under 200 lines including the consent notice, and it replaces a heavy iframe with an image and a button. The cost is one click before the game starts, plus one more for visitors who declined cookies, which is the honest order of things anyway.
If you only want the speed and not the consent step, you can drop the notice and keep the rest. The other way round does not work: a frame that loads on arrival has already contacted the game host by the time any banner asks a question. For what ad networks make of all this when they review a site, the post on ads.txt for game websites covers the file they check first.