Search code examples
nginxcachingbrowser-cachestatic-files

Cache static files dynamically


I'm working on a web project where we use Nginx to serve static files. I'd like to add the version on static files so that we could force the client to update static files that have been edited. Right now we handle that issue manually on each file by adding the version of the file (... scr="file.js?v=1234" ... ) but they are more and more files on the project.

I need help, an advice to handle files versions dynamically on server with Nginx so that when we edit the file, the version change dynamically and the client can automatically update to a newer version.

If it's seems to be impossible to handle with Nginx, I'm also open for all others solutions or advices.

Thanks


Solution

  • after some research, I found a way to cache files dynamically using webpack. It does exactly what I was searching for. The article is quit well explained here. It uses a hash function to identify changes on a file and add the hash in his name.