How To: Embed via backend integration
How to publish your Embeddable from the backend via Server-Side Rendering
One of the most powerful ways to publish an Embeddable is to serve it using Server-Side Rendering (SSR) from your backend.
To implement this, please reach out to the Embeddables team in order to:
- Discuss your tech stack and how the integration would work in your case (optional)
- Get the Embeddables team to enable this approach for your account (required)
Looking for other ways to publish your Embeddable? Check out the Publish to your site guide.
Embedding via backend SSR integration
Fetch the Embeddable data from our Renderer API endpoint
Within your backend code that serves your site, start by fetching the Embeddable data from our Renderer API endpoint.
You must pass all query parameters from the request to the Renderer API endpoint for all Embeddables features to work correctly.
Construct the HTML
Construct the necessary HTML pieces that will need to be included in the final HTML response.
This includes, in order of appearance:
- Boilerplate page styles (optional) - the minimum styles and meta tags to ensure the page is rendered correctly on all devices, if needed.
- Embeddables bundle script - this loads asynchronously and is the full JS code that makes the Embeddables interactive.
- Embeddable HTML - this is the initial rendering of the Embeddable, which is inserted here so that the end-user immediately sees the content, even before the bundle script has loaded.
- Embeddables Onload Script - this is some initial JS that runs immediately on load. It contains code that affects the initial load (e.g. choosing the correct breakpoint for the end-user’s device size), meaning that we can’t wait for the bundle script to load before executing it.
Combine into the final HTML response
Combine all the pieces. This is the final HTML response that should be sent to the client (along with any other HTML you want to include, e.g. fonts, scripts, etc.):
Complete code examples
Here’s the complete code example for a Node.js server using Express:
Here’s the complete code example for a Node.js server using Express:
Here’s a complete code example for a page served by a Cloudflare Worker:
Was this page helpful?