- Print
- DarkLight
- PDF
Cloudflare Integration for ESM Syntax
If you want to integrate Prerender into your site, the best approach is to incorporate it into your CDN if one is available. This integration specifically uses the ESM JavaScript syntax in Cloudflare Workers. Follow the guide below for step-by-step instructions on how to integrate Prerender with Cloudflare.
If you keep the SXGs option enabled, Cloudflare will display the cached version of your website pages to users who click on the page link on the search engine result pages.
However, keep in mind that Prerender is meant to create a static HTML file for search bots, so the rendered version may not be as responsive.
To avoid this issue we highly recommend disabling this setting in Cloudflare.
You can turn off Automatic Signed Exchanges by going to Speed -> Optimization -> Other (tab) in Cloudflare settings.
Video guide:
Copy the Cloudflare worker's source code from this link from here.
What are the steps to integrate Prerender with Cloudflare?
1. Create a new worker
Open your Cloudflare Dashboard and click on Workers & Pages on the left side
Then click on Create on the Worker Overview page.
Then click on the "Create Worker" button.
Give your worker a descriptive name. e.g.: prerender-worker
Click on the Deploy button at the bottom right to initialize the worker.
2. Add the Prerender worker's code
Click on "Edit Code"
Replace the example code with the worker's source code
Copy the Cloudflare worker's source code from this link.
Save the changes by clicking on Deploy.
3. Configure the worker
Step back to the previous interface by clicking on your worker's name on the top left.
Go to settings and add the zone and routes for your site.
Click on +Add at Domains & Routes
Select route
Type in your domain like this: *example.com/* and Select the Zone where your site is.
You can add a route specific to your subdomain. If you want to test Prerender on just one of your domains or subdomains, you can add another route to the worker later if needed.
Click on Add Route to save the setting.
4. Add the Prerender token as an Environment Variable.
Next to Variables and Secrets, click on +Add
Copy your Prerender token from your dashboard
Add your Prerender.io Token from the Security and Access menu.
Add a text variable named "PRERENDER_TOKEN" and set its value to the token from your dashboard. Then, click Deploy.