关于如何更改静态资产的文件名以防止过时的浏览器缓存版本的资产文件的想法

关于如何更改静态资产的文件名以防止过时的浏览器缓存版本的资产文件的想法

问题描述:

I have a website that I host with PHPFog. PHPFog, for those who don't know, makes it very easy to deploy an app to multiple application servers with a simple git-push. I would love it if there was some way to automatically update the version number of my javascript/css files with every git-commit or git-push. Or somehow maybe just append the 'build' unix timestamp to the filename. The goal of course to queue browsers to reload the asset file instead of going with the cached version. Does anyone know of a good way to do this?

我有一个用PHPFog托管的网站。 PHPFog,对于那些不知道的人来说,使用简单的git-push将应用程序部署到多个应用程序服务器非常容易。 如果有一些方法可以使用每个git-commit或git-push自动更新我的javascript / css文件的版本号,我会很高兴。 或者不知何故可能只是将'build'unix时间戳附加到文件名。 当然,目标是将浏览器排队以重新加载资产文件,而不是使用缓存版本。 有没有人知道这样做的好方法? p> div>

You can append a bogus query string to your CSS files - such as

styles.css?<?php print $release; ?>

The release identifier can be anything you want - perhaps a timestamp, git hashref, or tag.