Simple cache busting with Laravel

Most web servers are configured to send headers that tell browsers to store a local copy of all CSS, JavaScript, and images for a period of time. This local copy is called the cache.

This process not only helps alleviate the load on the server, but it also helps browsers render websites faster on subsequent page loads.

The problem however, is that we need a way to let browsers know when a file has been updated and needs to be downloaded again.

This is where cache busting comes in.
There are various ways to handle cache busting, but my favorite is to create a helper function that will automatically add a query string with a timestamp based on when the file was last modified.

This technique works because browsers consider unique query strings to represent different pages, even if the base path and filename are the same. This means every time the query string changes, browsers will re-download the file, therefor busting the cache.