Removing request urls via Workers?

With focus on Workers proxying and manipulating requests, I was curious if Workers would be suited to removing specific requests on specific url paths ? Haven’t see any examples of this.

For example say Workers assigned to* route and you have a site/script which is designed load /XXX.js javascript on everypage. But for specific url /page.php, you wanted to remove /XXX.js from loading on that page ? Could this be done with a Worker ?

Either regex replace the string contents or use the HTML rewriter.

If it’s only a few strings, then this is easier than using the HTML rewriter, you can just get the response body and do a replace on it.


Considering that workers are an official version of a MITM :wink: they certainly could pull that off.

You’d basically just need to tweak the output you receive from the origin in the way you like. What @thomas4 mentioned would be one possible option, for example.