Worker - Redirecting /* to /ajax/libs/*


@matteo Cloudflare engineering replied to the ticket and suggested that instead I put the latency onto the requests for resources at root and prioritise checking if the request exists at /ajax/libs and if it doesn’t, assuming the request is actually for a root file.

Does this code look right to achieve that?

addEventListener('fetch', event => {

async function fetchAndApply(request) {
  const requestURL = new URL(request.url)
  if(!requestURL.pathname.startsWith('/ajax/libs')) {
    requestURL.pathname = '/ajax/libs' + requestURL.pathname
    const newResponse = await fetch(requestURL, request)
    if(newResponse.status == 200) return newResponse
  return fetch(request)


That depends on the usage, if that makes sense it can be a good idea.

Looks good to me.



Brilliant, thank you for the help once again. Workers is something absolutely new to me so the community is always amazing to have around to help :slight_smile:



Just to give you an update, got the stats for Feb from Cf and 5 billion was right on the mark :tada:
141 billion in total for Feb :sunglasses:



Thanks for getting back to me! That is an impressive amount of traffic. Good job! Is the worker ok?

1 Like


I would assume the code is okay, engineering had no further comments regarding it.

They’re still working on getting it deployed as they need elevated internal access to do it, or something like that.

1 Like


Understandable that not everyone can mess with configurations on Cloudflare’s main domain.

1 Like


Yeah indeed! It seems the process for us getting stats is much faster now which is cool. Thank you for the help once again! I might remember to post another update here once we get it deployed :slight_smile: