toulax-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-18 17:29 UTC
Numbers on stylesheet_link_tag and image_tag
Can anyone explain to me exactly what are those numbers that rails appends to stylesheets and images when using stylesheet_link_tag or image_tag? At first I thought it would be so the browser wouldn''t cache the stylesheets, but that doesn''t make much sense for images, plus it seems that the numbers are unique, maybe based on the session. Any idea? Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The numbers in the url prevent the browser from caching images and stylesheets. (Since it''s a different URL each time the browser assumes they are different files.) On Feb 18, 11:29 am, "tou...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <tou...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Can anyone explain to me exactly what are those numbers that rails > appends to stylesheets and images when using stylesheet_link_tag or > image_tag? At first I thought it would be so the browser wouldn''t > cache the stylesheets, but that doesn''t make much sense for images, > plus it seems that the numbers are unique, maybe based on the session. > Any idea? > > Thanks--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> The numbers in the url prevent the browser from caching images and > stylesheets. (Since it''s a different URL each time the browser assumes > they are different files.)Actually, the numbers are there to make expiration easy while still retaining maximum cachability. So you setup your web server to cache all js, css, and images for 1 year. Now your users don''t have to spend precious sockets trying to fetch all the assets on every page load. That means faster page views. But how do you now let the user download new versions of the files you just told his browser to cache for 1 year? That''s where the asset magic number comes in. It''s actually a timestamp of the file. So what you''ve done is say to the browser, cache forever the all.js from 2006-12-12 (all.js?20061212). Now when you update all.js on January 4th, the file will be linked up as all.js?20070104. To the browser that''s a new file, thus it''ll fetch it again (and now save _that_ version for 1 year). If you for whatever (crazy) reason do not want your users to cache assets like this, you can set ENV[''RAILS_ASSET_ID''] = "". Then the magic will be gone. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
toulax-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-19 06:03 UTC
Re: Numbers on stylesheet_link_tag and image_tag
> Actually, the numbers are there to make expiration easy while still > retaining maximum cachability. > > So you setup your web server to cache all js, css, and images for 1 > year. Now your users don''t have to spend precious sockets trying to > fetch all the assets on every page load. That means faster page views. > > But how do you now let the user download new versions of the files you > just told his browser to cache for 1 year? That''s where the asset > magic number comes in. It''s actually a timestamp of the file. > > So what you''ve done is say to the browser, cache forever the all.js > from 2006-12-12 (all.js?20061212). Now when you update all.js on > January 4th, the file will be linked up as all.js?20070104. To the > browser that''s a new file, thus it''ll fetch it again (and now save > _that_ version for 1 year). > > If you for whatever (crazy) reason do not want your users to cache > assets like this, you can set ENV[''RAILS_ASSET_ID''] = "". Then the > magic will be gone.Thanks David, that makes a lot of sense. I was afraid the number was random or fixed, and in both cases it would be no good, but using the timestamp to refresh the file only when there''s a change is really handy! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---