Enable/Disable Rocket Loader via Fetch API in Workers

Is there any way to disable or enable Rocket Loader via “fetch” API? The docs don’t mention anything.

You should be able to. You need to call the API Endpoint. The code would look something like:


await fetch("https://api.cloudflare.com/client/v4/zones/:zone_id/settings/rocket_loader",   {
  method: 'PATCH',

  body: JSON.stringify({"value": "off"}),
  headers: {
     "Content-Type":  "application/json",
     "Authorization": "Bearer <api token here>"
 }
 )
1 Like

@Cyb3r-Jak3 no, I was talking about disabling Rocket Loader inside the content fetched via Fetch APi.

@gijovarghese141

You can use

fetch(event.request, { cf: { rocketLoader: false } })

@naveed1 where is it mentioned? Can you point me to the docs?

Nop :frowning:

I have been using the same for over a year in my workers script. I am pretty sure, I tested it that time and worked, but seems not working now. You can try asking in the discord.

@gijovarghese141

Phew… I was testing in the preview / playground. However when tested on production, fetch(event.request, { cf: { rocketLoader: false } }) worked.

Workers Preview doesn’t have access to a cf object. So I believe none of the cf init would work in preview.

I tested both the scenarios in production and live page.

Rocket Loaded turned on in Dashboard
Workers: cf: { rocketLoader: false }
Output: removes the rocketloader javascript originally added by Cloudflare.

Rocket Loaded turned off in Dashboard
Workers: cf: { rocketLoader: true }
Output: Adds the rocketloader javascript in the footer.

There are lot of things that are undocumented.

1 Like

Yes, it seems to be working! Thanks!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.