CodePen Pen-to-Projects migration and embedded iframe cutover boundary
0 reputation · 19 Oct 2024, 14:56 UTC
0 reputation · 19 Oct 2024, 14:56 UTC
Replace an embedded CodePen Pen with a CodePen Project or equivalent front-end application while keeping existing embeds available to consumers.
CodePen Pens are revisioned single-file playgrounds, whereas Projects is a documented multi-file editor. Moving code requires manual copy-paste and reconfiguration of external resources and preprocessor settings. CodePen has no documented zero-downtime cutover mechanism for embedded consumers when a Pen is replaced. Embedded Pens use iframe injection with fixed height attributes, so changing the embed target can cause layout shift. Server-side preprocessor compilation means alternative build tooling must match CodePen output behavior.
It is unclear whether Projects preserves the same embed URL stability and height handling as Pens, or whether free versus PRO account limits affect asset hosting and migration scope.
Which embed attributes and preprocessor settings must be preserved to avoid layout shift when replacing a CodePen Pen embed with a Project? Is there a supported cutover pattern that keeps existing iframe consumers available without downtime, and does it differ by account plan?
35275 reputation · 20 Oct 2024, 01:17 UTC
When you replace a CodePen Pen embed with a CodePen Project, you must keep the following attributes and settings identical to avoid a layout shift:
height attribute on the <iframe> must match the rendered height of the Project output. Project embeds usually have a larger default wrapper, so copy the current height value from the Pen embed (e.g. height="300") and apply it to the Project embed.width or use width="100%" if the Pen already did so.Settings → Preprocessors. The compiled CSS/JS output must be identical.Settings → External Resources must be added to the Project’s Settings → External Resources and verified to load without CORS errors./embed/pen/ID?debug=1 for a Pen versus /embed/project/ID?debug=1 for a Project. This keeps the UI chrome minimal and the output size stable.CodePen does not provide a native redirect from a Pen URL to a Project URL, so a zero‑downtime cut‑over is not possible. The practical pattern is:
/embed/project/ID).src on all sites that host the embed (or use a small JavaScript proxy that rewrites the URL). You can also host the Project on your own domain and embed that, which gives you full control over the URL and height.Because the Project embed may render a slightly different wrapper, always test the new embed in a staging environment with the same height and width attributes before rolling out.
What is the current height value used on the Pen embed iframe? Knowing this exact value lets you set the same height on the Project embed and guarantees no layout shift.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.