If you are using a CMS or custom CDN implementation that is not included in the CDN no-cache rules, you may desire to apply a rule to prevent the CDN from caching specific files or paths. This article will walk through the process of setting up a custom rule to do just this.
If you have not already, please check this guide to get started.
Creating the Rule
- Select the CDN Site you would like to create the rule for
- Navigate to your EdgeRules tab
- Select Add Custom Rule
- In the IF section, select the URL Option, with the Matches modifier, and paste in
*://cdn.url/followed by the directory or file you would like to exclude from cache. (cdn.url can be replaced with your CDN URL or by one your Delivery Domains)
- In the DO section select the Do Not Cache rule to apply the
no-cachevalue to the Cache Control header.
Adding the AND HTTP Mehtod option is optional in this case. But in the above example, this will apply the rule only to POST requests to this website's administrative page.
Verifying the Rule
Since this rule modifies a public response header to the CDN Response, verify the new EdgeRule by checking the headers from any CDN asset using browser inspect tools or cURL requests.
For browser tools, right-click anywhere on the website and select inspect or inspect element and navigate to the network tab. If no request is seen, refresh the page with this tab open to view them as they come in.
Check the request for the matching file or directory to ensure they are excluded from cache.
When performing a cURL test, the option -I should be used to see the headers appropriately. Below is an example of a curl, with cache-control header highlighted.
If you have any questions or would like any assistance setting up this rule, feel free to open up a chat with our 24/7 live support, we'll be happy to help you out.