问题描述
我有通过Amazon Cloudfront提供的JS和CSS文件。直到现在,我一直在使用自己的运行Varnish的服务器,并且当我更新任何JS或CSS文件时,或者必须使用该新版本时,都是在该文件请求的URL参数上增加一个计数器。
I have JS and CSS files being served through Amazon Cloudfront. Up until now I was using my own server running Varnish, and when I updated any JS or CSS file or I had to do to use that new version was to increase a counter on a URL param on the request for that file.
因此,所包含文件的URL从... / file.css?r = 1变为... / file.css?r = 2,Varnish会认为
So the URL of the file being included would go from .../file.css?r=1 to .../file.css?r=2 and Varnish would think of that as a new file, request it and cache it and serve it from cache from that point on.
使用Cloudfront,我意识到它无法像那样作为新文件进行请求并对其进行缓存并从那时起将其提供给缓存。 ,它仍然提供旧的缓存文件(并且我在HTTP响应中一直从Cloudfront命中)。
With Cloudfront I'm realizing it doesn't work like that, it still serves the old cached file (and I keep getting "hit from Cloudfront" on the HTTP response).
任何想法,如果我可以更改Cloudfront的行为,这个?
Any idea if I can change the behavior of Cloudfront for this?
我还能做的其他事情并不意味着每次更新文件时实际上都会更改文件名吗?我也不想通过Cloudfront的API使用缓存失效。我认为这对我在这里要做的工作来说太多了,我每个月可以进行的(免费)请求数量有限。
Anything else I can do that doesn't imply actually changing the name of the file everytime I update the file? I also don't want to use cache invalidations through Cloudfront's API. I think that's too much work for what I'm trying to do here, and there's a limited amount of (free) requests per month I can make.
推荐答案
看起来您还早一个月……2012年5月中旬,亚马逊宣布您可以开始使用查询字符串来识别云前端缓存中的对象。
Looks like you were about a month too early... in mid-May of 2012, Amazon announced that you could start using query strings to identify objects in your cloud front cache.
以下是其博客上的公告的链接:
Here's a link to the announcement on their blog: http://aws.typepad.com/aws/2012/05/amazon-cloudfront-support-for-dynamic-content.html
不幸的是,我没有在我的快速谷歌搜索中看到任何链接来描述您可以如何执行此操作,但是我敢肯定它被埋在了他们的文档或控制面板中。
Unfortunately, I don't see any links in my quick googling that describes how exactly you can do this but I'm sure it's buried in their documentation or control panel somewhere.
希望这会使您朝正确的方向前进。
Hope this gets you going in the right direction.
这篇关于向Amazon Cloudfront上的文件添加URL参数(?p = 234)不会强制刷新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!