We are hosting a PHP application with multiple javascript files. Currently we bust the cache by appending a get parameter (timestamp) to the url of the javascript files, ie: http://ourserver.com/scripts/something.js?cachebust=1289438903
As the number of files increase the performance of the application decreases. What are the various solutions we could use to mitigate this problem, from js build systems to apache2 configurations? What options require the least amount of changes in our application code and our current development workflow?
What we do is have a php script that takes the files that need to be minified and combined and creates an url of those. The script does that and also creates a hash of the concatenation of the version numbers of all the files. The hash is appended to the url as a
&hash=<hash>parameter. The script generated something like this:This is sent tot the client and the browser does the request. The minifier script takes the parameters, minifies them (or takes them from cache), concatenates them and sends them back. Because the hash is a function of the version of the scripts it will be renewed when one of the files change. And because the version only changes when the file changes no unnecessary cache busts will take place. There are multiple scripts that do this. We use wro4j (in java), but php scripts exist.
Edit: To be able to bugfix in production we also have a parameters
debug=truethat will tell the minifier script to not actually minify and just return the concatenated script.