Provides methods for linking a HTML page together with other assets, such as javascripts, stylesheets, and feeds.
Constants
JAVASCRIPT_DEFAULT_SOURCES = ['prototype', 'effects', 'dragdrop', 'controls'] unless const_defined?(:JAVASCRIPT_DEFAULT_SOURCES)
Attributes
![Default_avatar_30](https://www.gravatar.com/avatar/829c8d2766e8a97c2a0c477974192ddb?default=http://apidock.com/images/default_avatar_30.png&size=30)
Alternative hostname generation method
Instead of using a random number to generate the hostname for the single asset, I prefer using source.hash.modulo, so that a given file is always served from the same host. This makes the content more cacheable by browsers and proxies.
ActionController::Base.asset_host = Proc.new { |source| "http://assets#{ source.hash.modulo(9) }.example.com" }
I didn’t benchmark how long it takes, but String#hash should be reasonably fast.
![Default_avatar_30](https://www.gravatar.com/avatar/61d9814eda64f06b83e78a2ac4f2a059?default=http://apidock.com/images/default_avatar_30.png&size=30)
RE: Alternative hostname generation method
According to compute_asset_host as of rails 2.0.0 the %d expansion works in the same way, it’s not a random number generated on each call but the source hash mod 4.
In my brief testing in rails 2.3.9, %d doesn’t appear to work if you use a Proc, so manual generation is of use in that case.