# Image\_tag adding request parameter

**URL:** <https://www.ruby-forum.com/t/image-tag-adding-request-parameter/57406>\
**Category:** Rails\
**Created:** [April 10, 2006, 6:12pm UTC](https://www.ruby-forum.com/t/image-tag-adding-request-parameter/57406 "2006-04-10T18:12:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![thiagoalessio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d6d6ee/32.png) [@thiagoalessio](https://www.ruby-forum.com/u/thiagoalessio)\
**Post date:** [April 10, 2006, 6:12pm UTC](https://www.ruby-forum.com/t/image-tag-adding-request-parameter/57406/1 "2006-04-10T18:12:30Z")

</div>

I have noticed that the image\_tag helper method now appends a request  
parameter to the generated src attribute. With Rails  
1.0/actionpack-1.11.2 I had

![](https://test.ruby-forum.com/images/rss.gif)

Now (1.1/1.12.1) I get

![Rss](https://test.ruby-forum.com/images/rss.gif?1142366545)

Is there any use for that number? Where does it come from?

This is very far from critical and is in no way a breaking change (at  
least for me), but I am curious to know why things changed.

Cheers,

Thiago A.

---

<div class="post-metadata">

**Author:** ![thiagoalessio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d6d6ee/32.png) [@thiagoalessio](https://www.ruby-forum.com/u/thiagoalessio)\
**Post date:** [April 10, 2006, 6:24pm UTC](https://www.ruby-forum.com/t/image-tag-adding-request-parameter/57406/2 "2006-04-10T18:24:43Z")

</div>

Changelog:

Added automated timestamping to AssetTagHelper methods for  
stylesheets, javascripts, and images when Action Controller is run  
under Rails [DHH]. Example:

image\_tag(“rails.png”) # =\> ‘ ![Rails](https://www.ruby-forum.com/images/rails.png?1143664135)’

?to avoid frequent stats (not a problem for most people), you can set  
RAILS\_ASSET\_ID in the ENV to avoid stats:

ENV[“RAILS\_ASSET\_ID”] = “2345”  
image\_tag(“rails.png”) # =\> ‘ ![Rails](https://www.ruby-forum.com/images/rails.png?2345)’

This can be used by deployment managers to set the asset id by  
application revision

---

<div class="post-metadata">

**Author:** ![thiagoalessio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d6d6ee/32.png) [@thiagoalessio](https://www.ruby-forum.com/u/thiagoalessio)\
**Post date:** [April 10, 2006, 6:52pm UTC](https://www.ruby-forum.com/t/image-tag-adding-request-parameter/57406/3 "2006-04-10T18:52:29Z")

</div>

Edward F. \<epfrederick@…\> writes:

> Added automated timestamping to AssetTagHelper methods for  
> stylesheets, javascripts, and images when Action Controller is run  
> under Rails [DHH]. Example:

That’s quit extreme, screwing up caches _by default_ to please a few  
corner  
cases that can’t handle dynamic content properly. The example below is  
specially  
bad:

> image\_tag(“rails.png”) # =\> ‘ ![Rails](https://www.ruby-forum.com/images/rails.png?1143664135)’

“/images” will usually live under public, so it is _static_. Why add  
timestamping to a static resource? At worse, these tags should add  
timestamping  
only in the rare case where the image path is actually mapped _to_ an  
action  
controller (not _from_ a controller).

That, or I’m really missing something…

– Pazu

---

<div class="post-metadata">

**Author:** ![thiagoalessio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d6d6ee/32.png) [@thiagoalessio](https://www.ruby-forum.com/u/thiagoalessio)\
**Post date:** [April 10, 2006, 7:01pm UTC](https://www.ruby-forum.com/t/image-tag-adding-request-parameter/57406/4 "2006-04-10T19:01:34Z")

</div>

I thought the purpose of this is the browser cache. If a ressource file  
gets  
changed, it’s changed at the browser with the next request. Especially  
important for IE (in case there are pople still using it…).

---

<div class="post-metadata">

**Author:** ![thiagoalessio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d6d6ee/32.png) [@thiagoalessio](https://www.ruby-forum.com/u/thiagoalessio)\
**Post date:** [April 11, 2006, 3:20pm UTC](https://www.ruby-forum.com/t/image-tag-adding-request-parameter/57406/5 "2006-04-11T15:20:13Z")

</div>

> Browser cache is a Good Thing ™. It avoids repeated requests for resources  
> that don’t change (hence the name ‘static resources’), saving network traffic,  
> reducing the load in your application, loading pages faster and generally making  
> the user happier.
> 
> Of course, you need to understand how the browser cache (and http caches in  
> general) works, and play well with it. The rules are actually quite simple, and  
> it doesn’t take much to make sure browsers will cache what they can, and refetch  
> what they should.

Do you think timestamping that was added breaks caching in any way? From  
what  
I see it helps, not breaks. Timestamp is not some random value, but time  
of the  
file modification, so it in fact helps in cases when  
“If-modified-since” and “If-none-match”  
don’t play nice.

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)

---

<div class="post-metadata">

**Author:** ![thiagoalessio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d6d6ee/32.png) [@thiagoalessio](https://www.ruby-forum.com/u/thiagoalessio)\
**Post date:** [April 11, 2006, 2:52pm UTC](https://www.ruby-forum.com/t/image-tag-adding-request-parameter/57406/6 "2006-04-11T14:52:37Z")

</div>

Roberto S. \<rsaccon@…\> writes:

> I thought the purpose of this is the browser cache. If a ressource file gets  
> changed, it’s changed at the browser with the next request. Especially  
> important for IE (in case there are pople still using it…).

Browser cache is a Good Thing ™. It avoids repeated requests for  
resources  
that don’t change (hence the name ‘static resources’), saving network  
traffic,  
reducing the load in your application, loading pages faster and  
generally making  
the user happier.

Of course, you need to understand how the browser cache (and http caches  
in  
general) works, and play well with it. The rules are actually quite  
simple, and  
it doesn’t take much to make sure browsers will cache what they can, and  
refetch  
what they should.

– Pazu

---

<div class="post-metadata">

**Author:** ![thiagoalessio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d6d6ee/32.png) [@thiagoalessio](https://www.ruby-forum.com/u/thiagoalessio)\
**Post date:** [April 11, 2006, 10:44pm UTC](https://www.ruby-forum.com/t/image-tag-adding-request-parameter/57406/7 "2006-04-11T22:44:44Z")

</div>

Rimantas L. \<rimantas@…\> writes:

> Timestamp is not some random value, but time of the  
> file modification

I knew I was missing something 😉 From the messages above, I had the  
impression  
that ‘timestamp’ was referring to some value generated at request time,  
and not  
the actual file timestamp. You’re right, done this way, timestamping  
will only  
help caching instead of hurting it.

– Pazu
