Usage:
1) using asset hosts
ActionController::Base.asset_host = "assets.example.com"
image_tag("rails.png")
=> <img src="http://assets.example.com/images/rails.png" alt="Rails" />
stylesheet_link_tag("application")
=> <link href="http://assets.example.com/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
ActionController::Base.asset_host = "assets%d.example.com"
ActionController::Base.asset_host = Proc.new { |source| "http://assets#{rand(2) + 1}.example.com" }
2) using asset timestamps
rails will append all assets with the asset's timestamp
note that in order for this to work, all your application servers must return the same timestamps. This means that they must their clocks synchronized. To avoid the request for assets over and over again from a random host.
Code Reading:
ASSETS_DIR = defined?(Rails.public_path) ? Rails.public_path : "public" # check the asset dir is setup
JAVASCRIPTS_DIR = "#{ASSETS_DIR}/javascripts" # the convention js dir
STYLESHEETS_DIR = "#{ASSETS_DIR}/stylesheets" # the convention css dir
1) auto_discovery_link_tag(type = :rss, url_options = {}, tag_options = {})
# Returns a link tag that browsers and news readers can use to auto-detect an RSS or ATOM feed.
2) javascript_path(source)
compute_public_path(source, 'javascripts', 'js')
# Computes the path to a javascript asset in the public javascripts directory. if source has no extension, '.js' will be appended.