Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Caching tricks with Cloudflare Workers (dev.to)
6 points by dhxt on June 11, 2019 | hide | past | favorite | 2 comments



This example could be simplified somewhat if you're willing to leak the generated `ua` query parameter back to the origin server. Most servers will simply ignore unexpected query parameters, so this is likely to work fine.

In that case, you could change the fetch() call to:

    response = await fetch(newRequest);
And then make sure you set a page rule to "cache everything" on your whole site (otherwise by default HTML won't be cached since it's often dynamic).

Then you can remove the explicit `cache.match()` and `cache.put()` calls from this example, since the `fetch()` call will implicitly perform the caching you want.

(I'm the tech lead of Cloudflare Workers.)


I tried doing this before. The problem was that passing additional query parameters to Django admin caused it to crash. I traced the error down to conflicting lookup query parameters for some views (https://github.com/django/django/blob/9e38ed0536c7dc598a6c2c...), but didn't dig deeper than that. Passing through the unmodified request to Django resolved the problem.

You're right however, a simplified version probably works for 99% web servers (as long as the query parameters don't conflict with the ones used by your app), but unfortunately it didn't work for my use case.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: