Adding a URL parameter (? P = 234) to a file on Amazon Cloudfront does not update the file

I have JS and CSS files that are submitted through Amazon Cloudfront. So far I have used my own server running Varnish, and when I updated any JS or CSS file, or I had to do this to use this new version, I had to increase the counter by the URL parameter in the request for this file.

So the url of the included file will go from ... /file.css? r = 1 to ... /file.css? r = 2, and Larnis thinks of it as a new file, ask him to cache it and serve it from the cache from this point.

In Cloudfront, I understand that it doesn’t work like that, it still serves the old cached file (and I always get a “hit from Cloudfront” in the HTTP response).

Any idea if I can change Cloudfront's behavior for this?

Anything else I can do, does this mean that you change the file name every time I update the file? I also do not want to use cache invalidation through the Cloudfront API. I think there is too much work for what I'm trying to do here, and there are a small number of (free) requests per month that I can do.

+6
source share
3 answers

It looks like you were about a month earlier ... in mid-May 2012, Amazon announced that you could start using query strings to identify objects in the cloud front cache.

Here's a link to an ad on my blog: http://aws.typepad.com/aws/2012/05/amazon-cloudfront-support-for-dynamic-content.html

Unfortunately, I don’t see links to my quick Google search, which describes exactly how you can do this, but I’m sure that he’s buried somewhere in his documentation or control panel.

Hope this helps you move in the right direction.

+3
source

Unfortunately, if you want to avoid renaming files, then the invalidity through the CloudFront API remains the only option available. However, the pain of renaming files can be minimized by automating the deployment process.

+1
source

The short answer is no. CDN should be used for static assets that do not change often.

From docs :

When CloudFront requests an object from the source server, it removes any query string parameters.

Make sure your server is configured correctly to pass the Expires and / or Cache-Control: max-age headers. We are currently using max-age = 1800

0
source

Source: https://habr.com/ru/post/905463/


All Articles