What does this random number do: /javascripts/rails.js? 1271798101
I think I remember reading that it has to do with the browser not supposed to cache it or something. How does this affect browser caching and application performance in production? When does this number change?
<script src="/javascripts/rails.js?1271798101" type="text/javascript"></script>
a source to share
This does not mean that the browser does not cache it. The browser caches each query line separately, so what if the next query is rails.js? 9283482934, this is the new url to be requested from the server.
This allows you to tell the browser to cache the file, but by updating the html file with the new number, you can force all client browsers to download the new version without changing the new js file.
The reason for using this number is to allow clients to cache it, but also allows it to be forced to be updated, so it shouldn't negatively impact performance. However, if you programmatically generate a random number for each request, you will be forcing all clients to always request a file, effectively disabling caching for that file.
a source to share
The number is the last modified time of the file, as the number of seconds since Unix (if you run stat -c "%Y" javascripts/rails.js
on unix, you will get the same number added to the script tag). This number will change the next time the file is changed.
What it does is tell your browser that it can cache this javascript file and keep using the cached version until you change the file and hence the number is changed.
a source to share