Worker that Generates and serves and .xml sitemap?

Hi there,

Does anyone perhaps have a worker that can generate a dynamic xml sitemap and serve it to Google Search Console. I’ve got a number of Webflow sites that don’t quite gell with Cloudflare, so I had to Switch off SSL on th Webflow Origin servers and then had Cloudflare serve the sites with SSL. The sites work just fine, but the dynamic sitemap that Webflow generates is now listing all pages as http instead of https because as far as Webflow knows there’s no SSL. Basically I’m just hoping someones created a Worker that can generate and keep a sitemap up to date. The reason I use Webflow is that it’s no-code, so I don’t have the skills to create a worker myself. Please should if you know of a worker that can generate a sitemap.

I do. Workers that use xml-js or fast-xml-parser. If you need to just change http to https several times in a document, maybe just String.prototype.replaceAll() will do.
Note: not tested

let result = body.replaceAll("http", "https");

This will work for smallish XML sitemaps, but not for larger ones like > 500kb.
For that, use the HTML Rewriter and stream the response and replacement.

1 Like

Could you elaborate on why this wouldn’t work? I’m just curious as I’ve never used replaceAll or HTML Rewriter in Workers :slightly_smiling_face:

500KB should be able to comfortably fit in memory and I don’t see how HTML Rewriter would do better in terms of CPU time.

As soon as you put data into a variable, the worker will need to parse that data - eating up the CPU time to do it. From my tests, the worker can only parse ~1MB of data while staying under the 50ms. So in theory, you could have that amount in XML here, but I suggest having margins.

Is that with HTML Rewriter?