How to invalidate a SPA app without prefix purge?

What is the name of the domain?

demo.pencilitout.com

What is the issue you’re encountering

Specific URL invalidation uses pre-rule URLs. For a SPA, this is the entire space of the customer accounts and unique IDs.

What steps have you taken to resolve the issue?

Read lots of docs.

What are the steps to reproduce the issue?

Attempt to invalidate just the changed files instead of all of the static files. For example, given demo.pencilitout.com/index.html, demo.pencilitout.com/assets/23fageh.js, demo.pencilitout.com/assets/23fageh.css, and demo.pencilitout.com/static/very_large_file.pdf, I’d like to invalidate the first three but not the very_large_file.pdf.

However, SPA URLs look something like this: demo.pencilitout.com/analysis/AAAAAA/deal/BBBBBB where the AAAAAA and BBBBBB are very different for every customer.

All of these URLs are mapped via rule to demo.pencilitout.com/index.html in R2.

Because the “exact url invalidate” requires the pre-rule URL and not the post-URL rule, this appears to make it impossible to invalidate just the assets that haven’t changed.

If you have access to Purge Prefix, then you’d also be able to use Cache Tags, but you’d have to set those up ahead of time.

1 Like

If I had access to prefix, I could use that. If I had access to tags, I could use those. I’m not on the enterprise plan, however.

You won’t be able to purge prefix with exclusions.

That shouldn’t be the case. Cache Key is the origin URL:

Your Rule is like the Worker in this example:

https://developers.cloudflare.com/workers/reference/how-the-cache-works/#single-file-purge-assets-cached-by-a-worker

I still have my fingers crossed that Flexible Purge will show up soon as mentioned in a blog post here:

https://blog.cloudflare.com/instant-purge/#whats-next

I could, theoretically, use prefix just fine because my static assets are under a sub-url. As it is, I have to do a full cache invalidation or no invalidation at all, which sucks.

Cache Key is the browser URL. As per https://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-single-file/:

If you have a Transform Rule in place that is modifying part of a URL path, you must use the non-transform (end user) URL when performing single file purge so that purge can take effect.

That looks like a special case for Transform rules and Purge URL. That is not how a Purge Prefix works, as I just tested it. For Purge URL, both look to be interchangeable.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.