Worker - Remove Cache for Specified URL's

cache

#1

I have the following code for a Worker to remove the Ehid from the URL

But I need to remove it for specified URL’s within this script. I’m not sure how to do that and was wondering if anyone could maybe with this? I don’t want it to cache different parts of my sites/paths e.g images etc

thanks!

addEventListener(‘fetch’, event => {
event.respondWith(fetchAndLog(event.request))
})

/**

  • Fetch and log a given request object

  • @param {Request} request
    */
    async function fetchAndLog(request) {
    if (request.url.includes(‘ehid’)) {
    let url = new URL(request.url)

    //delete the ehid query param for the url
    //in the same way you can remove other parameters
    url.searchParams.delete(‘ehid’)

    //preserve the method and headers from the original request
    let init = {
    method: request.method,
    headers: request.headers
    }
    console.log(url.toString())
    //fetch the cached endpoint (without the ehid)
    const response = await fetch(url, init)
    return response
    }