Hi, I was just wondering what the advantage is to using the image_tag helper over the standard <img> html tag? Also the helper seems to place a load of random numbers on the end, eg ''?63565665'' why does it do this and what are they for? cheers josh -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 04 Apr 2007, at 16:19, josh wrote:> I was just wondering what the advantage is to using the image_tag > helper > over the standard <img> html tag? > > Also the helper seems to place a load of random numbers on the end, eg > ''?63565665'' why does it do this and what are they for?It''s the modification date of the image/stylesheet/javascript file. Browsers cache these files. This would mean that if you replace an image with the same filename, you''d have to refresh your browser for the change to show up (which can lead to some unexpected results). The extra numbers at the end will change if you replace the file, making the browser load them instead of resorting to the cached version. If the file is still the same, the extra numbers will also stay the same and the browser will use its cache. This has come up dozens of times on the list, a google search would probably have given you this answer too :-) Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
josh wrote:> I was just wondering what the advantage is to using the image_tag helper > over the standard <img> html tag? > > Also the helper seems to place a load of random numbers on the end, eg > ''?63565665'' why does it do this and what are they for?There are a few reasons to use image_tag over <img>. One is easy typing for a programmer. Compare: image_tag(''foo'') vs. <img src="/images/foo.png" /> Which would you rather type? Another is asset timestamping comes for free. Those are those funny numbers on the end. They are the timestamp of the file. This allows you to enable HTTP caching of images forever but still allow them to expire when you update the image A final reason is you can configure your static assets to be stored on a different server that is built to serve static resources quickly. A simple config change and all your images change from: <img src="/images/foo.png?63565665" /> to <img src="http://assets.yourcompany.com/images/foo.png?63565665" /> You don''t have to change all that code manually. Even if you choose to serve the static assets from the same server as dynamic requests you might still want to do this because the popular browsers limit the number of connections to each host to three requests. Setting up different virtual hosts (even if they are actually the same server) allows you to bypass this limit so your page can be loaded quicker. You get all that and more from using image_tag instead of <img>. Eric --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Long
2007-Apr-05 05:18 UTC
Re: [Bulk] [Rails] Re: why use image_tag helper and not <img> tag
Eric Anderson wrote:> > josh wrote: > > I was just wondering what the advantage is to using the image_tag helper > > over the standard <img> html tag? > > > > Also the helper seems to place a load of random numbers on the end, eg > > ''?63565665'' why does it do this and what are they for? > > There are a few reasons to use image_tag over <img>. One is easy typing > for a programmer. Compare: > > image_tag(''foo'') vs. <img src="/images/foo.png" /> >[snip]> > You get all that and more from using image_tag instead of <img>. >Good explanation. Note howerver, the use of helpers are optional. One can certainly do without the bells and whistles, especially if you are at all concerned about page rendering speed. While I do use some helpers I try to use them as few times as possible, but that is just my preference. -- Long http://MeandmyCity.com/ - Find your way http://edgesoft.ca/blog/read/2 - No-Cookie Session Support plugin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---