Caching for same URL but different content

Hi there,

So I have a file sharing site, with URLs that are in the form of, for example:


The first visit from a specific IP address within an hour will present the download information page which contains filename, size, and more importantly, the ads that fund the site. The actual download button goes to the same URL as above, except this time, because the IP already exists, will trigger a download of the file.

My question is - how can I tell Cloudflare to cache the file transfer, but not the initial page request? Because it’s the same URL, if I use normal Cache-Control then it would look the same.

Could I use ETags here (different ones for the download page vs download file)?
What’s the recommended best practice for this kind of setup?


I think your best bet is to use Page Rules and url variables.

http://site/download/*/ - bypass cache
Instead of loading this same url again for the file, simply add a bogus url variable (see next rule)

http://site/download/*/?download - cached

  1. In the origin server, have two separate URLs. Set page rules to cache only the one you want.
  2. Make the download button a POST request.
  3. Use the Cloudflare service worker to detect the two cases, and proxy the correct response.

This is slightly different from what you asked though. If a user clicks the link to reach the site multiple times, or will always show the HTML page with download button.
(You may be able to add recaptcha of required). I assume this is what you want.

If you really want the download automaticaly from second time onwards, then set some cookie.


Thanks, I think that’s basically what I need. I’ll try it out and see if it works!


This topic was automatically closed after 31 days. New replies are no longer allowed.