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?
In the origin server, have two separate URLs. Set page rules to cache only the one you want.
Make the download button a POST request.
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.