Rewrite Image URLs in CSS files using Service Workers

I’m using a separate CDN for delivering images. I’ve rewritten all images in the HTML using HTMLRewriter. However, some images like background images’ URLs are present inside CSS files and I want to rewrite them.

Is there anything like HTMLRewriter for CSS? If not, what is the best performant way to parse and rewrite images in css files?

For now, download the whole content, search and replace using regex seems to be the only solution. Not sure if there any better way.

Hello,
Sorry you didn’t get any reply at the time here.
Did you find a solution to rewrite in the CSS files?
Another user shared the following in case it can help: