问题原文
原帖链接 · CaptainCodeman · CC BY-SA 4.0
I have seen a number of articles suggesting the use of a query string to force refresh of a cached file. For example, style.css becomes style.css?ver=134, and you update the "version number" whenever you change the file.
Are there any potential problems with this method? If so, is there an alternative?
社区高分解答
原帖链接 · Maximillian Laumeister · CC BY-SA 4.0
This idea is called "cache busting", and there aren't any problems with your method that I'm aware of. It's a common, solid method that works reliably.
The other common alternative, of course, is to version the file path itself (e.g. /styles/v134/style.css or /styles/style-v134.css).
There's one final method that I've found useful in a niche circumstance: static site generators. If you have a static generated site that you don't update that often, you can have the site generator append the site's build time to URLs for all your versioned resources, e.g. /styles/style.css?t=(unix-time-stamp). This has the advantage of you not needing to manually update your file versions when each file changes, but has the disadvantage of cache busting ALL your resources every time you push an update.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
