views:

23

answers:

1

As I'm diving into RoR, I'm learning about some of the view asset tags and trying to undertand the benefit of using them instead of just using straight html. For example, what's the benefit, aside from brevity, of using <%= stylesheet_link_tag "main" %> instead of just writing out the actual HTML? Then I came across the cache option that allows the server to send multiple stylesheets in one download and that seems like a huge benefit. My questions are...

  1. Are there any downsides to using the cache option? Without knowing much about RoR, it would seem to me like you would definitely and always want to do this simply to reduce the number of requests your browser needs to make. True?
  2. If you're not using the cache option, what's the benefit (aside from brevity) of using the stylesheet_link_tag or javascript_link_tag instead of just writing the HTML it generates?

Thanks so much in advance for your wisdom!

+1  A: 
  1. There are no downsides except one: your application will boot a little bit slower due to the time required to package your assets. Also, some environments don't let you use the :cache option (for example, Heroku has a read-only filesystem), this is the reason why this feature is an option.
  2. There are a couple of benefits, including the ability to use asset host sharding, timestamp generation for asset caching and relative path resolution.
Simone Carletti