Class Merb::Assets::UniqueAssetPath
In: merb-assets/lib/merb-assets/assets.rb
Parent: Object

Helper for creating unique paths to a file name Can increase speend for browsers that are limited to a certain number of connections per host for downloading static files (css, js, images…)

Methods

Public Class methods

Builds the path to the file based on the name

Parameters

filename<String>:Name of file to generate path for

Returns

String:The path to the asset.

Examples

  build("/javascripts/my_fancy_script.js")
  # => "https://assets5.my-awesome-domain.com/javascripts/my_fancy_script.js"

[Source]

    # File merb-assets/lib/merb-assets/assets.rb, line 75
75:         def build(filename)
76:           config = Merb::Plugins.config[:asset_helpers]
77:           #%{#{(USE_SSL ? 'https' : 'http')}://#{sprintf(config[:asset_domain],self.calculate_host_id(file))}.#{config[:domain]}/#{filename}}
78:           path = config[:use_ssl] ? 'https://' : 'http://'
79:           path << sprintf(config[:asset_domain],self.calculate_host_id(filename)) << ".#{config[:domain]}"
80:           path << "/" if filename.index('/') != 0
81:           path << filename
82:         end

Protected Class methods

Calculates the id for the host

[Source]

    # File merb-assets/lib/merb-assets/assets.rb, line 87
87:         def calculate_host_id(filename)
88:           ascii_total = 0
89:           filename.each_byte {|byte|
90:             ascii_total += byte
91:           }
92:           (ascii_total % Merb::Plugins.config[:asset_helpers][:max_hosts] + 1)
93:         end

[Validate]