views:

79

answers:

2

I think I remember reading that that has to do with telling the browser not to cache it or something. How does this impact browser caching and application performance in production? When does that number change?

<script src="/javascripts/rails.js?1271798101" type="text/javascript"></script>
+1  A: 

It doesn't really tell the browser not to cache it -- The browser caches each query string individually, so if the next request is to rails.js?9283482934, that is a new URL that needs to be requested from the server.

That lets you tell the browser to cache the file, but by updating the html file with a new number, you can force all client browsers to download the new version without actually changing the new of the js file.

The reason to use the number is to allow clients to cache it but also allow you to force an update -- so it should not negatively affect the performance. However, if you are programmatically generating a random number for each request, you will be forcing all clients to always request the file, effectively disabling caching for that file.

Chris Shaffer
+6  A: 

The number is the last modified time of the file, as number of seconds since the Unix epoch (if you ran stat -c "%Y" javascripts/rails.js in unix, you would get the same number as is appended in the script tag). That number will change the next time you modify the file.

What it does is tell your browser that it can cache that javascript file, and keep using the cached version until you modify the file and thus the number is changed.

Daniel Vandersluis