1

I've been using Fastly CDN for a bunch of static assets like images and so on, and I'd like to use it for my javascript and css as well but I'm wary that it won't update if I push new code and that this will cause errors.

I know I could just set up a system to automatically purge this stuff, but I'd rather not have to. Based on one or two tests, I have the sense that heroku detects static file changes and purges them from fastly, but I don't see anywhere that says I can rely on this. Does somebody know for sure?

MalcolmOcean
  • 2,807
  • 2
  • 29
  • 38

2 Answers2

1

Fastly will use the TTL (time to live) of the object to determine when to refetch the object from origin. The TTL can be set via a Surrogate-Control: max-age, Cache-Control: s-maxage|max-age, or Expires header. If the file is updated on the origin but the TTL has not expired within the Fastly servers, Fastly will continue to serve the old content. With near real-time purge, you can avoid this situation by adding the purge api call (https://docs.fastly.com/api/purge) to your application. When you push new code also issue a purge call. This will force Fastly to fetch the new content on the next request.

Cassandra
  • 11
  • 1
  • 1
    Right, but that's a bit of a pain... and I don't want to have to purge everything, just files that have changed... – MalcolmOcean Oct 19 '15 at 03:19
  • 1
    You can use surrogate keys and corresponding surrogate key purges to restrict purges to the resources that changed. This doesn't require you to know the extent of URI paths that have changed and can in many cases simplify this task. – dho Oct 19 '15 at 16:13
0

No it doesn't. It follows the Cache-Control headers. You can use asset fingerprinting to name your static files with a hash code and timestamp, so each deploy will have a new file name and automatically not be in the cache. I don't know how it works in Node but here's how it works in Rails and Yii:

http://guides.rubyonrails.org/asset_pipeline.html#what-is-fingerprinting-and-why-should-i-care-questionmark

http://www.yiiframework.com/doc-2.0/guide-structure-assets.html#cache-busting

Here's what Fastly says about it

https://devcenter.heroku.com/articles/fastly#expired-assets

Chloe
  • 25,162
  • 40
  • 190
  • 357