A cache rule can make a known public asset path eligible for edge caching. Scope the rule to content that is identical for all visitors and keep private application responses outside that scope.
IN THIS ARTICLE
Check access and requirements
Identify a static directory or exact asset pattern and inspect its response headers. Confirm it does not contain authenticated downloads, user-specific exports or URLs whose extension disguises a dynamic route.
01 Create a cache rule for public static assets
- Open Rules and create a Cache Rule for the intended zone.
- Name the rule by its purpose and match the exact hostname plus the public asset path or appropriate condition. Avoid matching all traffic for a narrow asset task.
- Choose Eligible for cache and use the origin’s deliberate cache policy unless an override is specifically justified.
- Review the rule’s position against other cache rules, especially private-page bypass rules. Deploy after checking the expression.
- Request representative files as anonymous and signed-in users, inspect CF-Cache-Status and confirm the content is safe to share across visitors.
02 Example: make one public build-assets directory eligible for cache
Assume static.example.com/assets/ contains only public CSS, JavaScript and images produced by your build. After checking that no authenticated exports or user-specific downloads live there, create a Cache Rule using this narrow expression.
http.host eq "static.example.com" and
starts_with(http.request.uri.path, "/assets/") and
http.request.method in {"GET" "HEAD"}
Choose Eligible for cache and begin with the origin’s deliberate cache policy. For long-lived caching, versioned filenames let the next deployment publish a different URL when bytes change. Eligibility alone does not override every response condition or prove the file was stored.
Expected result: Repeated requests for an intended public asset can use edge cache without changing the main application’s login or checkout policy. A file with private or no-store directives is investigated at its source rather than made public merely to achieve a HIT.
Confirm the expected result
The intended public files should become cacheable without changing private routes. Evaluate multiple requests and locations because the first request at an edge may be a miss.
Resolve setup problems
Eligibility does not guarantee storage: response headers, cookies, status and other controls can still prevent caching. Do not remove private or no-store headers merely to obtain a HIT. Correct the application’s public-asset delivery where appropriate.
Should I cache everything to make the site faster?
Only after a full application-specific design. Login, cart, account and personalised pages can leak or mix data if treated like public files. Start with a clearly public asset scope.