I am really curious… what is up with the random number being
appended to the query string of calls to JS, CSS and Image files? At
first I thought it was just for development mode so that files would
not be cached but when I went to my site in production mode the random
number where appended as well. Does anyone know the design decision
behind this? Or if the number really is random?
Is their a function to get that random number for when I create my own
helpers?
I am really curious… what is up with the random number being
appended to the query string of calls to JS, CSS and Image files? At
first I thought it was just for development mode so that files would
not be cached but when I went to my site in production mode the random
number where appended as well. Does anyone know the design decision
behind this? Or if the number really is random?
Is their a function to get that random number for when I create my own helpers?
Added automated timestamping to AssetTagHelper methods for
stylesheets, javascripts, and images when Action Controller is run
under Rails [DHH]. Example:
image_tag(“rails.png”) # => ‘’
â?¦to avoid frequent stats (not a problem for most people), you can set
RAILS_ASSET_ID in the ENV to avoid stats:
Thanks Rimantas… I appreciate it. Stilld does not explain why
though. I am a big why type of guy. Anyone know why?
The reason for the timestamps on assets is to deal with browser
caching. Browsers tend to cache css and js for a while when they have
the same name and url. This just forces the browser to reload the css
or js or image when you make changes to it. This way your users don’t
get stale assets that don’t match the html like they should. Its
especially helpful in dev mode when often you are making frequent
changes to the css and js and you want them to reload in the browser
without the need for you to flush your browsers cache.
I understand this is very helpful in dev mode but is this a good thing
in production mode? Downloading the CSS file every single time the
user accesses a page of yours slows things down doesn’t it. Isn’t one
of the benefits of putting CSS in a seperate file the fact that it can
be cached?
Do people tend to turn this off for production?
I thought it was appended with the date the file was last saved. I could
definitely be wrong though.
I understand this is very helpful in dev mode but is this a good thing
in production mode? Downloading the CSS file every single time the
user accesses a page of yours slows things down doesn’t it. Isn’t one
of the benefits of putting CSS in a seperate file the fact that it can
be cached?