Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

middleman - asset path for CDN at build time

I want to do the following

if build?
    assetPath = "//cdn.domain.com/assets"
else
    assetPath = "assets"
end

trying all combinations and reading everywhere but simply stumped at the moment

ruby and middleman - still learning.

like image 459
Ian Warner Avatar asked Jul 02 '13 19:07

Ian Warner


2 Answers

Are you trying this within the config.rb? If not, you should do so.

There already is a setting that you might want to use ...

set :css_dir, 'assets'

... and change on build:

configure :build do
  set :css_dir, '//cdn.domain.com/assets'
end

Are you aware of the Asset helpers? You can use ...

<%= stylesheet_link_tag 'foo.css' %>

... within your (ERB) templates.

While developing that should give you ...

<link href="/assets/foo.css" media="screen" rel="stylesheet" type="text/css" />

... and within your build:

<link href="//cdn.domain.com/assets/foo.css" media="screen" rel="stylesheet" type="text/css" />
like image 132
Volker Rose Avatar answered Sep 21 '22 17:09

Volker Rose


I actually had problems with the early answer. To actually change the asset path to work with CDNs such as CloudFront, I had to do the following:

# Fingerprint assets
activate :asset_hash

# Enable Asset Hosts
activate :asset_host

set :asset_host do |asset|
  '//d23xxk856.cloudfront.net'.to_s
end
like image 39
Arthur Bierere Avatar answered Sep 17 '22 17:09

Arthur Bierere