Caching
Can a response ever be cached? I'm noticing it always downloads the resource I request even if it hasn't changed.
I would like to work on this enhancement. Can I start working on this?
Hi. Thanks for working on this. I'm noticing that I'm still getting a 200 response instead of 304. It's still downloading the resource. I don't see an etag in the response headers from cloudflare. Is this working as intended?
Some websites don't manage etag response header.
For me everything is cached. I need to fetch new data on every 15s. Is there a way to bypass cache?
I put in a hack which greatly improves performance. It returns a 304 if the user has a cached version and doesn't check to see if there is a new version. Change processRequest to return a 304 if the request come with an etag.
async function processRequest(req, res) {
const startTime = new Date()
const params = parseParams(req)
if (params.requestMethod === 'OPTIONS') {
return res.end()
}
let page = { 'status':304, }
if( typeof req.headers['if-none-match'] !=='undefined' ) {
return res.status(304).send()
}
else {
page = await getPage(params)
}
return createResponse(page, params, res, startTime)
}
Is there a way to prevent the server from returning a cached response? I'm getting a resource in a previous state when I know it has changed since the last time I fetched it.
same. would like to bypass cache please
Would also like to force uncached requests. Maybe allow uncached when this header is send:
{headers: {'Cache-Control': 'no-cache'}}
I was able to get uncached results by appending a random number as a get parameter. See below.
fetch('https://api.allorigins.win/get?url=' + encodeURIComponent(url) + '&rand=' + Math.random())