Why use image_tag helper and not <img> tag

Hi,

I was just wondering what the advantage is to using the image_tag helper
over the standard 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

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 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 :slight_smile:

Best regards

Peter De Berdt

Eric A. wrote:

image_tag(‘foo’) vs.

[snip]

You get all that and more from using image_tag instead of .

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

josh wrote:

I was just wondering what the advantage is to using the image_tag helper
over the standard 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 . One is easy typing
for a programmer. Compare:

image_tag(‘foo’) vs.

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:

to

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 .

Eric